﻿using netDxf;
using netDxf.Blocks;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.TextFormatting;

namespace TestDxfDocument
{

    class insert
    {
        public static void dp(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double scale = 10.0;
            double x = 0;

            Vector2 p0 = new Vector2(100, 100);
            double pi = 3.1415926535897;
            double rnj = scale * 9.525 / 2.0;
            double dphd = scale * 3.97;
            string path = Convert.ToString(data["path"]);
            //            double rnj = scale*19.05 / 2.0;
            //            double dphd = scale*4.76;
            Circle circle1 = new Circle(p0, scale * 2.2);
            Circle circle2 = new Circle(p0, scale * 3);
            Circle circle3 = new Circle(p0, rnj);
            circle3.Linetype = Linetype.DashDot;

            Vector2 p1 = new Vector2(p0.X + rnj * Math.Sin(7 * pi / 180), p0.Y - rnj * Math.Cos(7 * pi / 180));
            double lp1p2 = rnj / Math.Tan(37 * pi / 180);
            Vector2 p2 = new Vector2(p1.X + lp1p2 * Math.Cos(7 * pi / 180), p1.Y + lp1p2 * Math.Sin(7 * pi / 180));
            double lp3p2 = scale * 0.8 / Math.Sin(37 * pi / 180);
            Vector2 p3 = new Vector2(p2.X - lp3p2 * Math.Cos(30 * pi / 180), p2.Y + lp3p2 * Math.Sin(30 * pi / 180));
            Vector2 p5 = new Vector2(p3.X + scale * 0.8 * Math.Sin(7 * pi / 180), p3.Y - scale * 0.8 * Math.Cos(7 * pi / 180));
            Vector2 p4 = new Vector2(p3.X + scale * 0.8 * Math.Cos(23 * pi / 180), p3.Y + scale * 0.8 * Math.Sin(23 * pi / 180));
            Vector2 p6 = new Vector2(p0.X, p0.Y - rnj / Math.Cos(7 * pi / 180) + scale * 0.8 / Math.Cos(7 * pi / 180));
            Vector2 p7 = new Vector2(p6.X - scale * 0.8 * Math.Sin(7 * pi / 180), p6.Y - scale * 0.8 * Math.Cos(7 * pi / 180));
            Vector2 p8 = new Vector2(p6.X + scale * 0.8 * Math.Sin(7 * pi / 180), p6.Y - scale * 0.8 * Math.Cos(7 * pi / 180));
            Vector2 p9 = new Vector2(p0.X + (rnj - scale * 0.8) / Math.Cos(7 * pi / 180) * Math.Cos(30 * pi / 180), p0.Y + (rnj - scale * 0.8) / Math.Cos(7 * pi / 180) * Math.Sin(30 * pi / 180));
            Vector2 p10 = new Vector2(p9.X + scale * 0.8 * Math.Cos(23 * pi / 180), p9.Y + scale * 0.8 * Math.Sin(23 * pi / 180));

            //           Vector2 p11 = Vector2.Polar(p10, 5,45);

            Arc arc1 = new Arc(p6, scale * 0.8, 270 - 7, 270 + 7);
            Line line1 = new Line(p8, p5);
            line1.Layer = contour;
            Arc arc2 = new Arc(p3, scale * 0.8, 270 + 7, 23);
            Line line2 = new Line(p4, p10);
            line2.Layer = contour;

            Line[] linepoarray = new Line[1000];
            linepoarray = fun.arraypoline(line1, 3, p0);
            for (int i = 1; i <= 3; i++)
            {
                dxf.AddEntity(new EntityObject[] { linepoarray[i] });
            }

            Arc[] arcpoarray = new Arc[1000];
            arcpoarray = fun.arraypoarc(arc1, 3, p0);
            for (int i = 1; i <= 3; i++)
            {
                dxf.AddEntity(new EntityObject[] { arcpoarray[i] });
            }

            Line[] linepoarray1 = new Line[1000];
            linepoarray1 = fun.arraypoline(line2, 3, p0);
            for (int i = 1; i <= 3; i++)
            {
                dxf.AddEntity(new EntityObject[] { linepoarray1[i] });
            }

            Arc[] arcpoarray1 = new Arc[1000];
            arcpoarray1 = fun.arraypoarc(arc2, 3, p0);
            for (int i = 1; i <= 3; i++)
            {
                dxf.AddEntity(new EntityObject[] { arcpoarray1[i] });
            }

            dxf.AddEntity(new EntityObject[] { circle1, circle2, circle3 });

            Vector2 p0p = new Vector2(p0.X + 200, p0.Y);
            Vector2 p11 = new Vector2(p0p.X, p0p.Y + scale * 3);
            Vector2 p12 = new Vector2(p11.X - scale * 0.88, p11.Y);
            Vector2 p13 = new Vector2(p12.X - (scale * 3 - scale * 2.2) / Math.Tan(30 * pi / 180), p12.Y - (scale * 3 - scale * 2.2));
            Vector2 p14 = new Vector2(p11.X - dphd, p13.Y);
            Vector2 p16 = new Vector2(p0p.X, p0p.Y + fun.distance1(p0, p3) + scale * 0.8);
            Vector2 p15 = new Vector2(p14.X, p16.Y - dphd * Math.Tan(11 * pi / 180));

            Vector2 p17 = new Vector2(p0p.X, p0p.Y - scale * 3);
            Vector2 p18 = new Vector2(p12.X, p17.Y);
            Vector2 p19 = new Vector2(p13.X, p0p.Y - scale * 2.2);
            Vector2 p20 = new Vector2(p14.X, p19.Y);
            Vector2 p22 = new Vector2(p0p.X, p0p.Y - (rnj - scale * 0.8) / Math.Cos(7 * pi / 180) - scale * 0.8);
            Vector2 p21 = new Vector2(p20.X, p22.Y + dphd * Math.Tan(11 * pi / 180));

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p14));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p16));
            //poly.SetConstantWidth(0.5);
            poly.IsClosed = true;

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p17));
            poly1.Vertexes.Add(new LwPolylineVertex(p18));
            poly1.Vertexes.Add(new LwPolylineVertex(p19));
            poly1.Vertexes.Add(new LwPolylineVertex(p20));
            poly1.Vertexes.Add(new LwPolylineVertex(p21));
            poly1.Vertexes.Add(new LwPolylineVertex(p22));
            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;


            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>
            {
                new HatchBoundaryPath(new List<EntityObject> {poly}),
                new HatchBoundaryPath(new List<EntityObject> {poly1})
            };

            Hatch hatch = new Hatch(HatchPattern.Line, boundary, true);
            hatch.Pattern.Angle = 45;
            hatch.Pattern.Scale = 40;
            dxf.AddEntity(poly);
            dxf.AddEntity(poly1);
            dxf.AddEntity(hatch);

            Line line3 = new Line(p11, p17);
            Line line4 = new Line(p12, p18);
            Line line5 = new Line(p13, p19);
            Line line6 = new Line(p14, p20);
            dxf.AddEntity(line3);
            dxf.AddEntity(line4);
            dxf.AddEntity(line5);
            dxf.AddEntity(line6);

            DimensionStyle ds = fun.CreateDimStyle();
            ds.ArrowSize = textheight;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textheight;



            double offset = 30;
            LinearDimension dimX1 = new LinearDimension(new Line(p15, p16), offset, 0, ds);
            dimX1.UserText = String.Format("{0}", dphd / scale);
            dxf.AddEntity(dimX1);

            Line linep = new Line(p12, p13);
            AlignedDimension dim1 = new AlignedDimension(linep, offset * 2, ds);
            dim1.UserText = String.Format("{0}", Convert.ToInt32((fun.distance1(p12, p13) / scale) * 100) / 100.0);
            dxf.AddEntity(dim1);

            Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p1, p5), new Line(p10, p4), offset, ds);
            dimang1.SetDimensionLinePosition(new Vector2(p2.X - scale * 1.5 * Math.Cos(30 * pi / 180), p2.Y + scale * 1.5 * Math.Sin(30 * pi / 180)));
            dxf.AddEntity(dimang1);

            //            DimensionStyle myStyle = CreateDimStyle();
            DiametricDimension dimdia1 = new DiametricDimension(circle1, 15, offset, ds);//DimensionStyle.Default);
            dimdia1.UserText = String.Format("Φ{0}", 2 * 2.2);
            DiametricDimension dimdia2 = new DiametricDimension(circle2, 45, offset, ds);//DimensionStyle.Default);
            dimdia2.UserText = String.Format("Φ{0}", 2 * 3);
            DiametricDimension dimdia3 = new DiametricDimension(circle3, 135, offset, ds);// DimensionStyle.Default);
            dimdia3.UserText = String.Format("Φ{0}", 2 * rnj / scale);
            dxf.AddEntity(dimdia1);
            dxf.AddEntity(dimdia2);
            dxf.AddEntity(dimdia3);

            RadialDimension dimrad1 = new RadialDimension(arcpoarray[2], 45, 0.5 * offset, ds);//DimensionStyle.Default);
            dimrad1.UserText = String.Format("R{0}", 0.8);
            dxf.AddEntity(dimrad1);
            RadialDimension dimrad2 = new RadialDimension(arcpoarray1[2], 45, 0.5 * offset, ds);// DimensionStyle.Default);
            dimrad2.UserText = String.Format("R{0}", 0.8);
            dxf.AddEntity(dimrad2);

            Line line7 = new Line(new Vector2(p0.X + scale * (3 + 2), p0.Y), new Vector2(p0.X - scale * (3 + 2), p0.Y));
            line7.Layer = center;
            Line line8 = new Line(new Vector2(p0.X, p16.Y + 3), new Vector2(p0.X, p22.Y - 3));
            line8.Layer = center;
            Line line9 = new Line(new Vector2(p20.X - 3, p0p.Y), new Vector2(p0p.X + 3, p0p.Y));
            line9.Layer = center;
            dxf.AddEntity(line7);
            dxf.AddEntity(line8);
            dxf.AddEntity(line9);

            TextStyle style = new TextStyle("simsun.ttf");
            Text text = new Text("技术要求", new Vector3(10, -10, 0), 3.5f, 0, style);
            text.WidthFactor = 0.7;
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(new EntityObject[] { text });
            Text text1 = new Text("热处理HRC50", new Vector3(10, -15, 0), 3.5f, 0, style);
            text1.WidthFactor = 0.7;
            text1.Layer = new Layer("text");
            text1.Layer.Color.Index = 8;
            text1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(new EntityObject[] { text1 });

            fun.jz(dxf, new Vector2(10, 5), 45, 3, "B");
            fun.czd(dxf, new Vector2(10, 25), 0, "12.5");
            fun.czd(dxf, new Vector2(10, 45), 45, "12.5");
            fun.czd(dxf, new Vector2(10, 65), 135, "12.5");
            fun.czd(dxf, new Vector2(10, 85), -45, "12.5");
            fun.czd1(dxf, new Vector2(10, 105), 180, "12.5");
            fun.czd2(dxf, new Vector2(10, 125), -120, "12.5");
            fun.czd3(dxf, new Vector2(10, 145), 45, "1.6", "3.2");

            string[] zhp = { "zxd", "pmd", "yd", "yzd", "xlkd", "mlkd", "pxd", "czd", "qxd", "tzd", "dcd", "wzd", "ytd", "qtd", "zdstzt", "ysgcd", "bryz", "yx", "yxzt", "yxjx", "jzmbwd", "jt", "jzx", "bcfwwzfx" };

            for (int i = 1; i <= 24; i++)
            {
                fun.xwgcfh(dxf, new Vector2(-20, 10 + i * 25), zhp[i - 1]);
            }

            fun.gb118207(dxf, new Vector2(100, 5), new Vector2(100, 10), new Vector2(110, 10), new Vector2(120, 10), "%%c", "0.005", "qtd", "yxjx", "zdstzt", "B");

            fun.dimrot(dxf, new Vector2(140, 250), new Vector2(150, 310), -45, 40, 2.5, 2.5, 0, "Φ65.5", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(140, 250), new Vector2(150, 310), 45, 40, 2.5, 2.5, 0, "Φ65.5H7(", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(140, 250), new Vector2(150, 310), -135, 40, 2.5, 2.5, 0, "Φ65.5", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(140, 250), new Vector2(150, 310), 135, 40, 2.5, 2.5, 0, "Φ65.5H7(", "+0.1", "-0.006");

            fun.dimrot(dxf, new Vector2(140, 350), new Vector2(145, 355), 90, 40, 2.5, 2.5, 0, "Φ65.5H7(", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(140, 350), new Vector2(145, 355), -90, 40, 2.5, 2.5, 0, "Φ65.5", "+0.1", "-0.006");

            fun.dimrot(dxf, new Vector2(195, 455), new Vector2(190, 450), -90, 40, 2.5, 2.5, 0, "65.5H7(", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(195, 455), new Vector2(190, 450), 90, 40, 2.5, 2.5, 0, "65.5H7(", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(190, 450), new Vector2(195, 455), -178, 40, 2.5, 2.5, 0, "65.5", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(195, 555), new Vector2(190, 550), 178, 40, 2.5, 2.5, 0, "65.5H7(", "+0.1", "-0.006");
            fun.dimrot(dxf, new Vector2(195, 555), new Vector2(190, 550), 178, 80, 2.5, 2.5, 0, "65.5", "", "");

            fun.SetLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }


        public static void RhombicInsert(Dictionary<string, Object> data)    //菱形刀片，等边四边形刀片，适用于S,C,D,E,F,M,V型刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            /*
            double tic = 9.525;
            double scale = 1;*/
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5;
            //}

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);

            double offset = 10;

            /*
            double pi = Math.PI;
            double DIM =1;
            double ic = 9.525;
            double s = 4.76;
            double d1 = 3.81;
            double re = 1.2;
            int cb = 0;
            double epsr = 80 * pi / 180;
            double an = 7 * pi / 180;
            int ifs = 2;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = 0;
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc =0;
            double stc = 0;
            double d1tc = 0;
            */

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, epsr / 2, (ic / 2) / Math.Sin(epsr / 2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, epsr, le);
            Vector2 p4 = fun.Polar(p1, epsr, le);
            Vector2 p1p = fun.Polar(p1, epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p5 = new Vector2(p1p.X - re * (Math.Cos(pi / 2 - epsr)), p1p.Y + re * Math.Sin(pi / 2 - epsr));
            Vector2 p6 = new Vector2(p1p.X, p1p.Y - re);
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p7 = new Vector2(p2p.X, p2p.Y - re);
            Vector2 p8 = new Vector2(p2p.X + re * Math.Cos(pi / 2 - epsr), p2p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p9 = new Vector2(p3p.X + re * Math.Cos(pi / 2 - epsr), p3p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p10 = new Vector2(p3p.X, p3p.Y + re);
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));
            Vector2 p11 = new Vector2(p4p.X, p4p.Y + re);
            Vector2 p12 = fun.Polar(p4p, (pi / 2 + epsr), re);
            Vector2 p20 = fun.Polar(p0, 0, (ic * 4) + 2);
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));




            Vector2 v1 = fun.Polar(p0, 180 * pi / 180 + epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v3 = fun.Polar(p0, epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);



            if (cb == 1 || cb == 2)
            {

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);

            }


            Arc arc = fun.DrawArc(p5, p1p, p6);
            Circle circle1 = new Circle(p0, (d1 / 2.0));

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[2].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[6].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Layer = additionalline;
            dxf.AddEntity(line00);



            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);

            if (epsr == 35 * pi / 180)
            {
                inserthole(dxf, p0, v2, v3, fun.Polar(p20, 0, 2 * s), fun.Polar(p21, 0, 2 * s), scale, data);
                Line cenline3 = new Line(fun.Polar(fun.Polar(p20, 0, 2 * s), 0, 2), fun.Polar(fun.Polar(p20, 0, 2 * s), pi, s + 2));
                cenline3.Layer = center;
                dxf.AddEntity(cenline3);
            }
            else
            {
                inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
                Line cenline3 = new Line(fun.Polar(p20, 0, 2), fun.Polar(p20, pi, s + 2));
                cenline3.Layer = center;
                dxf.AddEntity(cenline3);
            }
            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) + 2), fun.Polar(p0, 0, (ic / 2) + 2));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) + 2), fun.Polar(p0, -pi / 2, (ic / 2) + 2));

            cenline1.Layer = center;
            cenline2.Layer = center;

            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);


            //fun.jz(dxf, fun.Polar(p4, 180 * pi / 180, 15), 90, 3.5, "A");
            fun.jz(dxf, fun.Polar(p4, pi, offset + Math.Abs(p1.X - p4.X)), 90, 3.5, "A");

            DimensionStyle ds = new DimensionStyle("ds");
            ds.ArrowSize = textheight;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textheight;
            Vector2 p100 = fun.Polar(p3, epsr, 0.1);
            Vector2 p101 = fun.Polar(p3, 0, 0.1);

            //标注
            if (DIM == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }



                LinearDimension dimX2 = new LinearDimension(new Line(p1, p4), offset + Math.Abs(p1.X - p4.X) / 2, 90, ds);
                dimX2.UserText = "IC";
                dxf.AddEntity(dimX2);

                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }
                /*
                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset , ds);
                dimang1.UserText = "EPSR";
                dxf.AddEntity(dimang1);*/





                fun.jdbz2(dxf, new Line(p3, p101), new Line(p3, p100), offset, textheight, textheight, 0.5, "EPSR=" + epsr * 180 / pi + "°", "", "");

                if (an != 0)
                {
                    /* Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, ds);
                     dimang2.UserText = "AN=" + an * 180 / pi + "°";
                     dxf.AddEntity(dimang2);*/

                    if (epsr != 35 * pi / 180)
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");
                    else
                    {
                        fun.jdbz2(dxf, new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(fun.Polar(p23, 0, 2 * s), pi - an, 1)), new Line(fun.Polar(p24, 0, 2 * s), fun.Polar(fun.Polar(p24, 0, 2 * s), pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");
                    }

                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p1, p4), offset + Math.Abs(p1.X - p4.X) / 2, 90, ds);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p1, p4), offset + Math.Abs(p1.X - p4.X) / 2, 90, ds);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dimX1.UserText = String.Format("S={0}", s / scale);
                        dxf.AddEntity(dimX1);
                    }
                    else
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dimX1.UserText = "S";
                        dxf.AddEntity(dimX1);
                    }


                }
                if (stc != 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                    else
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                }
                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }
                /*
                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset * 1.5, ds);
                dimang1.UserText = String.Format("EPSR={0}°", epsr * 180 / pi);
                dxf.AddEntity(dimang1);*/
                fun.jdbz2(dxf, new Line(p3, p101), new Line(p3, p100), offset, textheight, textheight, 0.8, "EPSR=" + epsr * 180 / pi + "°", "", "");

                if (an != 0)
                {
                    System.Diagnostics.Debug.WriteLine(666666666);
                    /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, ds);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                    if (epsr != 35 * pi / 180)
                        fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");
                    else
                    {
                        fun.jdbz2(dxf, new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(fun.Polar(p23, 0, 2 * s), pi - an, 1)), new Line(fun.Polar(p24, 0, 2 * s), fun.Polar(fun.Polar(p24, 0, 2 * s), pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");
                    }
                }
            }

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }


            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);
        }

        public static void TriangularInsert(Dictionary<string, Object> data)    //正三边形刀片，适用于T形刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double offset = 10;


            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            /*
            double tic = 9.525;
            double scale = 1;*/
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            // int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double le = 2 * ic * Math.Cos(pi / 6);
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            //double d1tc = Convert.ToDouble(data["d1tc"]);
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);

            double dxc = 0.8;

            /*
            double pi = Math.PI;
            double DIM = 1;
            double ic = 9.525* scale;
            double s =4.76 * scale;
            double d1 = 3.81 * scale;
            double re = 0.4 * scale;
            double epsr =60 * pi / 180;
            double an = 5 * pi / 180;
            // int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = 1;
            string path = Convert.ToString(data["path"]);
            double le = 2 * ic * Math.Cos(pi / 6);
            double ictc = 1;
            double stc = 0;
            //double d1tc = Convert.ToDouble(data["d1tc"]);
            double dxc = 0.8;
            String isframe_chose = "1";
            double isframe = 1;
            */
            /*
            double pi = Math.PI;
            double DIM = 1;
            double ic = 6.35 * scale;
            double s = 3.18 * scale;
            double d1 = 2.8 * scale;
            double re = 0.2 * scale;
            double epsr = 35 * pi / 180;
            double an = 5 * pi / 180;
            // int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = 1;
            string path = Convert.ToString(data["path"]);
            double le = 2 * ic * Math.Cos(pi / 6);
            double ictc = 1;
            double stc = 0;
            //double d1tc = Convert.ToDouble(data["d1tc"]);
            double dxc = 0.8;
            String isframe_chose = "1";
            double isframe = 1;
            */
            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, pi / 6, ic);
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p1, pi / 3, le);
            Vector2 p1p = fun.Polar(p1, pi / 6, 2 * re);
            Vector2 p2p = fun.Polar(p2, 5 * pi / 6, 2 * re);
            Vector2 p3p = fun.Polar(p3, -0.5 * pi, 2 * re);
            Vector2 p4 = fun.Polar(p1p, 5 * pi / 6, re);
            Vector2 p5 = fun.Polar(p1p, -0.5 * pi, re);
            Vector2 p6 = fun.Polar(p2p, -0.5 * pi, re);
            Vector2 p7 = fun.Polar(p2p, pi / 6, re);
            Vector2 p8 = fun.Polar(p3p, pi / 6, re);
            Vector2 p9 = fun.Polar(p3p, 5 * pi / 6, re);

            Vector2 p20 = fun.Polar(p0, 0, 4 * ic);
            Vector2 p21 = new Vector2(p20.X, p3p.Y + re);

            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

            Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);





            if (cb == 1 || cb == 2)
            {


                Line line15 = new Line(v1, v2);
                line15.Layer = additionalline;
                dxf.AddEntity(line15);
                Line line16 = new Line(v2, v3);
                line16.Layer = additionalline;
                dxf.AddEntity(line16);
                Line line17 = new Line(v1, v3);
                line17.Layer = additionalline;
                dxf.AddEntity(line17);

            }



            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Arc arc3 = fun.DrawArc(p8, p3p, p9);

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p4));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes[2].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);
            //poly11.Layer = contour;

            Line line12 = new Line(p1, p2);
            line12.Layer = additionalline;
            dxf.AddEntity(line12);
            Line line13 = new Line(p2, p3);
            line13.Layer = additionalline;
            dxf.AddEntity(line13);
            Line line14 = new Line(p1, p3);
            line14.Layer = additionalline;
            dxf.AddEntity(line14);



            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            Line cenline2 = new Line(fun.Polar(p0, 0.5 * pi, ic + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            Line cenline3 = new Line(fun.Polar(p20, 0, 2), fun.Polar(p20, pi, s + 2));
            Circle dotcircle1 = new Circle(p0, ic / 2);
            cenline1.Layer = center;
            cenline2.Layer = center;
            cenline3.Layer = center;
            dotcircle1.Layer = refin;

            //cenline1.Lineweight = Lineweight.W25;
            //cenline2.Lineweight = Lineweight.W25;
            //cenline3.Lineweight = Lineweight.W25;
            //cenline1.Linetype = Linetype.DashDot;
            //cenline2.Linetype = Linetype.DashDot;
            //cenline3.Linetype = Linetype.DashDot;

            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);
            dxf.AddEntity(dotcircle1);

            fun.jz(dxf, fun.Polar(fun.Polar(p0, 0, ic / 2), -90 * pi / 180, ic / 2 + offset), 0, 3.5, "A");

            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim2.UserText = "S";
                dxf.AddEntity(dim2);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                LinearDimension dim5 = new LinearDimension(new Line(p1, p2), offset * 2, 180, dimensionStyle);
                dim5.UserText = "LE";
                dxf.AddEntity(dim5);

                if (an != 0)
                {/*
                    Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim2);
                }
                if (stc != 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }


                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }
                LinearDimension dim5 = new LinearDimension(new Line(p1, p2), offset * 2.25, 180, dimensionStyle);
                dim5.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                dxf.AddEntity(dim5);

                if (an != 0)
                {

                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");


                }
            }

            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save(path);
        }

        public static void RoundInsert(Dictionary<string, Object> data)    //圆形刀片，适用于R形刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double offset = 10;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }
            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double dxc = 0.8;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            /*
            double pi = Math.PI;
            double DIM = 1;
            double ic = 6 * scale;
            double s = 2.38 * scale;
            double d1 = 2.8 * scale;
            double an = 7 * pi / 180;
            int ifs = 3;
            int cb = 1;
            double dxc = 0.8;
            double ictc = 1;
            double stc = 1;
            double d1tc = 1;
            double isframe = 1;
            string path = Convert.ToString(data["path"]);*/
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p20 = fun.Polar(p0, 0, 2 * ic);
            Vector2 p21 = new Vector2(p20.X, p20.Y + ic / 2);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p20.Y - ic / 2);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

            Vector2 v2 = fun.Polar(p0, -90 * pi / 180, ic / 2 * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 * dxc);

            if (cb == 1 || cb == 2)
            {
                Circle circle00 = new Circle(p0, ic / 2 * dxc);
                circle00.Layer = additionalline;
                dxf.AddEntity(circle00);

            }
            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            cenline1.Linetype = Linetype.Center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic / 2 + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            cenline2.Layer = center;
            cenline2.Linetype = Linetype.Center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);

            fun.drawcircle(dxf, p0, ic / 2, 0.2, contour);
            Circle circle2 = new Circle(p0, d1 / 2);
            circle2.Layer = contour;
            dxf.AddEntity(circle2);

            fun.jz(dxf, fun.Polar(fun.Polar(p0, 0, ic / 2), -90 * pi / 180, ic / 2 + offset), 0, 3, "A");
            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;

            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2 + 5), fun.Polar(p0, 0, ic / 2 + 5)), ic / 2 + offset, 180, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim2.UserText = "S";
                dxf.AddEntity(dim2);

                if (an != 0)
                {
                    /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), ic / 2 + offset, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), ic / 2 + offset, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim2);
                }
                if (stc != 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
                /*
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset * 1.5, 180, dimensionStyle);
                dim1.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim2.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim2);
                */
                if (an != 0)
                {
                    /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                   dimang2.UserText = "AN=" + an * 180 / pi + "°";
                   dxf.AddEntity(dimang2);*/
                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                }
            }
            //Angular2LineDimension dim4 = new Angular2LineDimension()


            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TrigonInsert(Dictionary<string, Object> data)    //凸三角刀片，w形刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double offset = 10;
            double textheight = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.80;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double ang1 = 40 * pi / 180;
            double ang2 = 80 * pi / 180;
            double ang3 = 10 * pi / 180;
            double ang4 = 30 * pi / 180;
            double le = (ic / Math.Tan(ang1) + ic / Math.Tan(ang2)) / 2;
            double dis1 = (ic / 2) / Math.Sin(ang1);
            double dis2 = (ic / 2) / Math.Sin(ang2);

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = new Vector2(le * Math.Cos(ang3), (ic / 2) / Math.Cos(ang3));
            Vector2 p2 = new Vector2(p0.X, p1.Y);
            Vector2 p3 = fun.Polar(p2, ang3, le);
            Vector2 p4 = fun.Polar(p3, pi - (ang2 - ang3), le);
            Vector2 p5 = fun.Polar(p0, pi / 2, dis1);
            Vector2 p6 = fun.Polar(p0, pi - ang4, dis2);
            Vector2 p7 = fun.Polar(p0, pi + ang4, dis1);
            Vector2 p2p = fun.Polar(p2, pi / 2, re / Math.Sin(ang2));
            Vector2 p3p = fun.Polar(p3, pi - ang4, re / Math.Sin(ang1));
            Vector2 p4p = fun.Polar(p4, pi + ang4, re / Math.Sin(ang2));
            Vector2 p5p = fun.Polar(p5, -0.5 * pi, re / Math.Sin(ang1));
            Vector2 p6p = fun.Polar(p6, -ang4, re / Math.Sin(ang2));
            Vector2 p7p = fun.Polar(p7, ang4, re / Math.Sin(ang1));
            Vector2 p8 = fun.Polar(p2, pi - ang3, re / Math.Tan(ang2));
            Vector2 p9 = fun.Polar(p2, ang3, re / Math.Tan(ang2));
            Vector2 p10 = fun.Polar(p3, pi + ang3, re / Math.Tan(ang1));
            Vector2 p11 = fun.Polar(p3, pi - (ang2 - ang3), re / Math.Tan(ang1));
            Vector2 p12 = fun.Polar(p4, ang3 - ang2, re / Math.Tan(ang2));
            Vector2 p13 = fun.Polar(p4, pi - (ang2 - ang4), re / Math.Tan(ang2));
            Vector2 p14 = fun.Polar(p5, ang4 - ang2, re / Math.Tan(ang1));
            Vector2 p15 = fun.Polar(p5, pi + ang2 - ang4, re / Math.Tan(ang1));
            Vector2 p16 = fun.Polar(p6, ang2 - ang4, re / Math.Tan(ang2));
            Vector2 p17 = fun.Polar(p6, pi + ang2 - ang3, re / Math.Tan(ang2));
            Vector2 p18 = fun.Polar(p7, ang2 - ang3, re / Math.Tan(ang1));
            Vector2 p19 = fun.Polar(p7, -ang3, re / Math.Tan(ang1));

            Vector2 p20 = fun.Polar(p0, 0, 2.3 * ic);
            Vector2 p21 = new Vector2(p20.X, fun.Polar(p5p, pi / 2, re).Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, fun.Polar(p2p, -pi / 2, re).Y); ;
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

            Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);
            Vector2 v4 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v5 = fun.Polar(p0, 30 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v6 = fun.Polar(p0, 150 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);


            if (cb == 1 || cb == 2)
            {
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v5));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v6));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
            }



            Circle circle2 = new Circle(p0, ic / 2);
            circle2.Layer = refin;
            circle2.Linetype = Linetype.DashDot;
            dxf.AddEntity(circle2);
            Arc arc5 = fun.DrawArc(p10, p3p, p11);

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes[0].Bulge = Math.Tan(ang3 / 2);
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes[2].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes[4].Bulge = Math.Tan(ang3 / 2);
            poly11.Vertexes.Add(new LwPolylineVertex(p13));
            poly11.Vertexes.Add(new LwPolylineVertex(p14));
            poly11.Vertexes[6].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p15));
            poly11.Vertexes.Add(new LwPolylineVertex(p16));
            poly11.Vertexes[8].Bulge = Math.Tan(ang3 / 2);
            poly11.Vertexes.Add(new LwPolylineVertex(p17));
            poly11.Vertexes.Add(new LwPolylineVertex(p18));
            poly11.Vertexes[10].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p19));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p5));
            line00.Vertexes.Add(new LwPolylineVertex(p6));
            line00.Vertexes.Add(new LwPolylineVertex(p7));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Layer = additionalline;
            dxf.AddEntity(line00);


            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            cenline1.Linetype = Linetype.Center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            cenline2.Layer = center;
            cenline2.Linetype = Linetype.Center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);


            fun.jz(dxf, fun.Polar(fun.Polar(p0, pi / 2, ic / 2), 180 * pi / 180, offset + p0.X), 90, 3, "A");
            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p1.X), 90, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim1.UserText = "S";
                dxf.AddEntity(dim2);

                Angular2LineDimension dim4 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, epsr / 2, 0.1)), new Line(p5, fun.Polar(p5, pi - epsr / 2, 0.1)), offset, dimensionStyle);
                dim4.UserText = "EPSR";
                dxf.AddEntity(dim4);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc5, -45, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                if (an != 0)
                {
                    /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p1.X), 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p1.X), 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim2);
                }
                if (stc != 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
                /*
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset * scale, 90, dimensionStyle);
                dim1.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim1.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim2);
                */
                Angular2LineDimension dim4 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, epsr / 2, 0.1)), new Line(p5, fun.Polar(p5, pi - epsr / 2, 0.1)), offset, dimensionStyle);
                dim4.UserText = String.Format("EPSR={0}°", epsr * 180 / pi);
                dxf.AddEntity(dim4);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc5, -45, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }

                if (an != 0)
                {
                    /*Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);*/
                    fun.jdbz2(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, textheight, textheight, 0.5, "AN=" + an * 180 / pi + "°", "", "");

                }
            }

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void PentagonalInsert(Dictionary<string, Object> data)    //p形刀片，正五边形
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double offset = 10;


            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);

            double ang1 = 108 * pi / 180;
            double ang2 = 54 * pi / 180;
            double ang3 = 72 * pi / 180;
            double ang4 = 36 * pi / 180;
            double le = ic / Math.Tan(ang2);

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, ang2, (ic / 2) / Math.Sin(ang2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, ang3, le);
            Vector2 p4 = fun.Polar(p3, pi - ang4, le);
            Vector2 p5 = fun.Polar(p4, pi + ang4, le);
            Vector2 p1p = fun.Polar(p1, ang2, re / Math.Sin(ang2));
            Vector2 p2p = fun.Polar(p2, pi - ang2, re / Math.Sin(ang2));
            Vector2 p3p = fun.Polar(p3, pi + ang4 / 2, re / Math.Sin(ang2));
            Vector2 p4p = fun.Polar(p4, 1.5 * pi, re / Math.Sin(ang2));
            Vector2 p5p = fun.Polar(p5, -ang4 / 2, re / Math.Sin(ang2));
            Vector2 p6 = fun.Polar(p1, ang1, re / Math.Tan(ang2));
            Vector2 p7 = fun.Polar(p1, 0, re / Math.Tan(ang2));
            Vector2 p8 = fun.Polar(p2, pi, re / Math.Tan(ang2));
            Vector2 p9 = fun.Polar(p2, ang3, re / Math.Tan(ang2));
            Vector2 p10 = fun.Polar(p3, -ang1, re / Math.Tan(ang2));
            Vector2 p11 = fun.Polar(p3, pi - ang4, re / Math.Tan(ang2));
            Vector2 p12 = fun.Polar(p4, -ang4, re / Math.Tan(ang2));
            Vector2 p13 = fun.Polar(p4, pi + ang4, re / Math.Tan(ang2));
            Vector2 p14 = fun.Polar(p5, ang4, re / Math.Tan(ang2));
            Vector2 p15 = fun.Polar(p5, -ang3, re / Math.Tan(ang2));

            Vector2 p20 = fun.Polar(p0, 0, 3 * ic);
            Vector2 p21 = new Vector2(p20.X, fun.Polar(p4p, pi / 2, re).Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));
            Vector2 v1 = fun.Polar(p0, -126 * pi / 180, ic / 2 / Math.Sin(54 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -54 * pi / 180, ic / 2 / Math.Sin(54 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Sin(54 * pi / 180) * dxc);
            Vector2 v4 = fun.Polar(p0, 18 * pi / 180, ic / 2 / Math.Sin(54 * pi / 180) * dxc);
            Vector2 v5 = fun.Polar(p0, 162 * pi / 180, ic / 2 / Math.Sin(54 * pi / 180) * dxc);


            if (cb == 1 || cb == 2)
            {
                LwPolyline line01 = new LwPolyline();
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Vertexes.Add(new LwPolylineVertex(v2));
                line01.Vertexes.Add(new LwPolylineVertex(v4));
                line01.Vertexes.Add(new LwPolylineVertex(v3));
                line01.Vertexes.Add(new LwPolylineVertex(v5));
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Layer = additionalline;
                dxf.AddEntity(line01);
            }

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p13));
            poly11.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p14));
            poly11.Vertexes.Add(new LwPolylineVertex(p15));
            poly11.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);



            Line line1 = new Line(p7, p8);
            Line line2 = new Line(p9, p10);
            Line line3 = new Line(p11, p12);
            Line line4 = new Line(p13, p14);
            Line line5 = new Line(p15, p6);
            Arc arc1 = fun.DrawArc(p6, p1p, p7);
            Arc arc2 = fun.DrawArc(p8, p2p, p9);
            Arc arc3 = fun.DrawArc(p10, p3p, p11);
            Arc arc4 = fun.DrawArc(p12, p4p, p13);
            Arc arc5 = fun.DrawArc(p14, p5p, p15);
            Circle circle1 = new Circle(p0, d1 / 2);
            Circle circle2 = new Circle(p0, ic / 2);
            circle1.Layer = contour;
            circle2.Layer = refin;
            circle2.Linetype = Linetype.DashDot;
            dxf.AddEntity(circle1);
            dxf.AddEntity(circle2);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p5));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Layer = additionalline;
            dxf.AddEntity(line00);



            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic / 2 + 2), fun.Polar(p0, -pi / 2, ic / 2 + 2));
            cenline2.Layer = center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Lineweight = Lineweight.W50;
            cenline3.Linetype = Linetype.Continuous;

            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);


            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            fun.jz(dxf, fun.Polar(fun.Polar(p0, pi / 2, ic / 2), 180 * pi / 180, offset + (p0.X - p5.X)), 90, textheight, "A");
            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p5.X), 90, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim2.UserText = "LE";
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = "S";
                dxf.AddEntity(dim3);

                RadialDimension dim4 = new RadialDimension(arc3, 45, offset, dimensionStyle);
                dim4.UserText = "RE";
                dxf.AddEntity(dim4);
                /*
                Angular2LineDimension dim5 = new Angular2LineDimension(new Line(p4, fun.Polar(p4, ang4, 0.1)), new Line(p4, fun.Polar(p4, pi - ang4, 0.1)), offset, dimensionStyle);
                dim5.UserText = "EPSR";
                dxf.AddEntity(dim5);*/


                fun.jdbz2(dxf, new Line(p4, fun.Polar(p4, ang4, 0.1)), new Line(p4, fun.Polar(p4, pi - ang4, 0.1)), offset, textheight, textheight, 0.4, "EPSR", "", "");



            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p5.X), 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + (p0.X - p5.X), 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim3);
                }
                if (stc != 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim3);
                }
                /*
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset+ic/2, 90, dimensionStyle);
                dim1.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim3);
                */
                LinearDimension dim2 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim2.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                dxf.AddEntity(dim2);


                RadialDimension dim4 = new RadialDimension(arc3, 45, offset, dimensionStyle);
                dim4.UserText = String.Format("RE={0}", re / scale);
                dxf.AddEntity(dim4);



            }

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }


            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void HexagonalInsert(Dictionary<string, Object> data)    //h形刀片，正六角形
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double offset = 10;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double ang1 = 30 * pi / 180;
            double ang2 = 60 * pi / 180;
            double le = ic * Math.Tan(ang1);

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, ang2, (ic / 2) / Math.Sin(ang2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, ang2, le);
            Vector2 p4 = fun.Polar(p3, pi - ang2, le);
            Vector2 p5 = fun.Polar(p4, pi, le);
            Vector2 p6 = fun.Polar(p5, pi + ang2, le);
            Vector2 p1p = fun.Polar(p1, ang2, re / Math.Sin(ang2));
            Vector2 p2p = fun.Polar(p2, pi - ang2, re / Math.Sin(ang2));
            Vector2 p3p = fun.Polar(p3, pi, re / Math.Sin(ang2));
            Vector2 p4p = fun.Polar(p4, pi + ang2, re / Math.Sin(ang2));
            Vector2 p5p = fun.Polar(p5, -ang2, re / Math.Sin(ang2));
            Vector2 p6p = fun.Polar(p6, 0, re / Math.Sin(ang2));
            Vector2 p7 = fun.Polar(p1, pi - ang2, re / Math.Tan(ang2));
            Vector2 p8 = fun.Polar(p1, 0, re / Math.Tan(ang2));
            Vector2 p9 = fun.Polar(p2, pi, re / Math.Tan(ang2));
            Vector2 p10 = fun.Polar(p2, ang2, re / Math.Tan(ang2));
            Vector2 p11 = fun.Polar(p3, pi + ang2, re / Math.Tan(ang2));
            Vector2 p12 = fun.Polar(p3, pi - ang2, re / Math.Tan(ang2));
            Vector2 p13 = fun.Polar(p4, -ang2, re / Math.Tan(ang2));
            Vector2 p14 = fun.Polar(p4, pi, re / Math.Tan(ang2));
            Vector2 p15 = fun.Polar(p5, 0, re / Math.Tan(ang2));
            Vector2 p16 = fun.Polar(p5, pi + ang2, re / Math.Tan(ang2));
            Vector2 p17 = fun.Polar(p6, ang2, re / Math.Tan(ang2));
            Vector2 p18 = fun.Polar(p6, -ang2, re / Math.Tan(ang2));

            Vector2 p20 = fun.Polar(p0, 0, 3 * ic);
            Vector2 p21 = new Vector2(p20.X, p4.Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));
            Vector2 v1 = fun.Polar(p0, -120 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -60 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 60 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);
            Vector2 v4 = fun.Polar(p0, 0 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);
            Vector2 v5 = fun.Polar(p0, 120 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);
            Vector2 v6 = fun.Polar(p0, 180 * pi / 180, ic / 2 / Math.Sin(60 * pi / 180) * dxc);

            if (cb == 1 || cb == 2)
            {
                LwPolyline line01 = new LwPolyline();
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Vertexes.Add(new LwPolylineVertex(v2));
                line01.Vertexes.Add(new LwPolylineVertex(v4));
                line01.Vertexes.Add(new LwPolylineVertex(v3));
                line01.Vertexes.Add(new LwPolylineVertex(v5));
                line01.Vertexes.Add(new LwPolylineVertex(v6));
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Layer = additionalline;
                dxf.AddEntity(line01);
            }


            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[0].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[2].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p13));
            poly11.Vertexes[4].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p14));
            poly11.Vertexes.Add(new LwPolylineVertex(p15));
            poly11.Vertexes[6].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p16));
            poly11.Vertexes.Add(new LwPolylineVertex(p17));
            poly11.Vertexes[8].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p18));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[10].Bulge = Math.Tan(60 * pi / 180 / 4);
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);


            LwPolyline line02 = new LwPolyline();
            line02.Vertexes.Add(new LwPolylineVertex(p1));
            line02.Vertexes.Add(new LwPolylineVertex(p2));
            line02.Vertexes.Add(new LwPolylineVertex(p3));
            line02.Vertexes.Add(new LwPolylineVertex(p4));
            line02.Vertexes.Add(new LwPolylineVertex(p5));
            line02.Vertexes.Add(new LwPolylineVertex(p6));
            line02.Vertexes.Add(new LwPolylineVertex(p1));
            line02.Layer = additionalline;
            dxf.AddEntity(line02);


            Line line1 = new Line(p8, p9);
            Line line2 = new Line(p10, p11);
            Line line3 = new Line(p12, p13);
            Line line4 = new Line(p14, p15);
            Line line5 = new Line(p16, p17);
            Line line6 = new Line(p18, p7);
            Arc arc1 = fun.DrawArc(p7, p1p, p8);
            Arc arc2 = fun.DrawArc(p9, p2p, p10);
            Arc arc3 = fun.DrawArc(p11, p3p, p12);
            Arc arc4 = fun.DrawArc(p13, p4p, p14);
            Arc arc5 = fun.DrawArc(p15, p5p, p16);
            Arc arc6 = fun.DrawArc(p17, p6p, p18);
            Circle circle1 = new Circle(p0, d1 / 2);
            Circle circle2 = new Circle(p0, ic / 2);

            circle1.Layer = contour;
            circle2.Layer = refin;
            circle2.Linetype = Linetype.DashDot;
            dxf.AddEntity(circle1);
            dxf.AddEntity(circle2);

            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            cenline1.Linetype = Linetype.Center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic / 2 + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            cenline2.Layer = center;
            cenline2.Linetype = Linetype.Center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);


            fun.jz(dxf, fun.Polar(fun.Polar(p0, pi / 2, ic / 2), 180 * pi / 180, offset + +(p0.X - p6.X)), 90, 3, "A");
            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + (p0.X - p6.X), 90, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim2.UserText = "LE";
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = "S";
                dxf.AddEntity(dim3);

                RadialDimension dim5 = new RadialDimension(arc4, 20, offset, dimensionStyle);
                dim5.UserText = "RE";
                dxf.AddEntity(dim5);
                /*
                Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, 0, 0.1)), new Line(p5, fun.Polar(p5, pi - ang2, 0.1)), offset, dimensionStyle);
                dim6.UserText = "EPSR";
                dxf.AddEntity(dim6);*/


                fun.jdbz2(dxf, new Line(p5, fun.Polar(p5, 0, 0.1)), new Line(p5, fun.Polar(p5, pi - ang2, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");


            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + +(p0.X - p6.X), 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + ic / 2, 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim3);
                }
                if (stc != 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim3);
                }
                /*
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset+ic/2, 90, dimensionStyle);
                dim1.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim3);
                */
                LinearDimension dim2 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim2.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                dxf.AddEntity(dim2);

                RadialDimension dim5 = new RadialDimension(arc4, 20, offset, dimensionStyle);
                dim5.UserText = String.Format("RE={0}", re / scale);
                dxf.AddEntity(dim5);

                /* Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, 0, 0.1)), new Line(p5, fun.Polar(p5, pi - ang2, 0.1)), offset, dimensionStyle);
                 dim6.UserText = String.Format("EPSR={0}°", epsr/(pi/180));
                 dxf.AddEntity(dim6); 
                 */
                fun.jdbz2(dxf, new Line(p5, fun.Polar(p5, 0, 0.1)), new Line(p5, fun.Polar(p5, pi - ang2, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");

            }

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void OctagonalInsert(Dictionary<string, Object> data)    //O形刀片，正八边形
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层



            double textheight = 3.5;
            double offset = 10;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double ang1 = 135 * pi / 180;
            double ang2 = 67.5 * pi / 180;
            double ang3 = 45 * pi / 180;
            double ang4 = ang2 - ang3;
            double le = ic / Math.Tan(ang2);

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = new Vector2(ic / 2, ic / 2);
            Vector2 p2 = fun.Polar(p0, pi + ang2, (ic / 2) / Math.Sin(ang2));
            Vector2 p3 = fun.Polar(p2, 0, le);
            Vector2 p4 = fun.Polar(p3, ang3, le);
            Vector2 p5 = fun.Polar(p4, pi / 2, le);
            Vector2 p6 = fun.Polar(p5, ang1, le);
            Vector2 p7 = fun.Polar(p6, pi, le);
            Vector2 p8 = fun.Polar(p7, pi + ang3, le);
            Vector2 p9 = fun.Polar(p8, 1.5 * pi, le);
            Vector2 p2p = fun.Polar(p2, ang2, re / Math.Sin(ang2));
            Vector2 p3p = fun.Polar(p3, pi - ang2, re / Math.Sin(ang2));
            Vector2 p4p = fun.Polar(p4, pi - ang4, re / Math.Sin(ang2));
            Vector2 p5p = fun.Polar(p5, pi + ang4, re / Math.Sin(ang2));
            Vector2 p6p = fun.Polar(p6, pi + ang2, re / Math.Sin(ang2));
            Vector2 p7p = fun.Polar(p7, -ang2, re / Math.Sin(ang2));
            Vector2 p8p = fun.Polar(p8, -ang4, re / Math.Sin(ang2));
            Vector2 p9p = fun.Polar(p9, ang4, re / Math.Sin(ang2));
            Vector2 p2s = fun.Polar(p2, ang1, re / Math.Tan(ang2));
            Vector2 p2e = fun.Polar(p2, 0, re / Math.Tan(ang2));
            Vector2 p3s = fun.Polar(p3, pi, re / Math.Tan(ang2));
            Vector2 p3e = fun.Polar(p3, ang3, re / Math.Tan(ang2));
            Vector2 p4s = fun.Polar(p4, pi + ang3, re / Math.Tan(ang2));
            Vector2 p4e = fun.Polar(p4, pi / 2, re / Math.Tan(ang2));
            Vector2 p5s = fun.Polar(p5, -0.5 * pi, re / Math.Tan(ang2));
            Vector2 p5e = fun.Polar(p5, ang1, re / Math.Tan(ang2));
            Vector2 p6s = fun.Polar(p6, -ang3, re / Math.Tan(ang2));
            Vector2 p6e = fun.Polar(p6, pi, re / Math.Tan(ang2));
            Vector2 p7s = fun.Polar(p7, 0, re / Math.Tan(ang2));
            Vector2 p7e = fun.Polar(p7, pi + ang3, re / Math.Tan(ang2));
            Vector2 p8s = fun.Polar(p8, ang3, re / Math.Tan(ang2));
            Vector2 p8e = fun.Polar(p8, -0.5 * pi, re / Math.Tan(ang2));
            Vector2 p9s = fun.Polar(p9, pi / 2, re / Math.Tan(ang2));
            Vector2 p9e = fun.Polar(p9, -ang3, re / Math.Tan(ang2));
            Vector2 v1 = fun.Polar(p0, -113 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -68 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v5 = fun.Polar(p0, -23 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v4 = fun.Polar(p0, 23 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 68 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v6 = fun.Polar(p0, 113 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v7 = fun.Polar(p0, 158 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);
            Vector2 v8 = fun.Polar(p0, -158 * pi / 180, ic / 2 / Math.Sin(67.5 * pi / 180) * dxc);



            if (cb == 1 || cb == 2)
            {
                LwPolyline line01 = new LwPolyline();
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Vertexes.Add(new LwPolylineVertex(v2));
                line01.Vertexes.Add(new LwPolylineVertex(v5));
                line01.Vertexes.Add(new LwPolylineVertex(v4));
                line01.Vertexes.Add(new LwPolylineVertex(v3));
                line01.Vertexes.Add(new LwPolylineVertex(v6));
                line01.Vertexes.Add(new LwPolylineVertex(v7));
                line01.Vertexes.Add(new LwPolylineVertex(v8));
                line01.Vertexes.Add(new LwPolylineVertex(v1));
                line01.Layer = additionalline;
                dxf.AddEntity(line01);
            }

            //Line line1 = new Line(p2e, p3s);
            //Line line2 = new Line(p3e, p4s);
            //Line line3 = new Line(p4e, p5s);
            //Line line4 = new Line(p5e, p6s);
            //Line line5 = new Line(p6e, p7s);
            //Line line6 = new Line(p7e, p8s);
            //Line line7 = new Line(p8e, p9s);
            //Line line8 = new Line(p9e, p2s);
            //Arc arc1 = fun.DrawArc(p2s, p2p, p2e);
            //Arc arc2 = fun.DrawArc(p3s, p3p, p3e);
            //Arc arc3 = fun.DrawArc(p4s, p4p, p4e);
            //Arc arc4 = fun.DrawArc(p5s, p5p, p5e);
            //Arc arc5 = fun.DrawArc(p6s, p6p, p6e);
            Arc arc6 = fun.DrawArc(p7s, p7p, p7e);
            //Arc arc7 = fun.DrawArc(p8s, p8p, p8e);
            //Arc arc8 = fun.DrawArc(p9s, p9p, p9e);
            //Circle circle1 = new Circle(p0, d1 / 2);
            Circle circle2 = new Circle(p0, ic / 2);
            //line1.Layer = contour;
            //line2.Layer = contour;
            //line3.Layer = contour;
            //line4.Layer = contour;
            //line5.Layer = contour;
            //line6.Layer = contour;
            //line7.Layer = contour;
            //line8.Layer = contour;
            //arc1.Layer = contour;
            //arc2.Layer = contour;
            //arc3.Layer = contour;
            //arc4.Layer = contour;
            //arc5.Layer = contour;
            arc6.Layer = contour;
            //arc7.Layer = contour;
            //arc8.Layer = contour;
            //circle1.Layer = contour;
            circle2.Layer = refin;
            circle2.Linetype = Linetype.DashDot;

            //dxf.AddEntity(line1);
            //dxf.AddEntity(line2);
            //dxf.AddEntity(line3);
            //dxf.AddEntity(line4);
            //dxf.AddEntity(line5);
            //dxf.AddEntity(line6);
            //dxf.AddEntity(line7);
            //dxf.AddEntity(line8);
            //dxf.AddEntity(arc1);
            //dxf.AddEntity(arc2);
            //dxf.AddEntity(arc3);
            //dxf.AddEntity(arc4);
            //dxf.AddEntity(arc5);
            //dxf.AddEntity(arc6);
            //dxf.AddEntity(arc7);
            //dxf.AddEntity(arc8);
            //dxf.AddEntity(circle1);
            dxf.AddEntity(circle2);


            LwPolyline line02 = new LwPolyline();
            line02.Vertexes.Add(new LwPolylineVertex(p2));
            line02.Vertexes.Add(new LwPolylineVertex(p3));
            line02.Vertexes.Add(new LwPolylineVertex(p4));
            line02.Vertexes.Add(new LwPolylineVertex(p5));
            line02.Vertexes.Add(new LwPolylineVertex(p6));
            line02.Vertexes.Add(new LwPolylineVertex(p7));
            line02.Vertexes.Add(new LwPolylineVertex(p8));
            line02.Vertexes.Add(new LwPolylineVertex(p9));
            line02.Vertexes.Add(new LwPolylineVertex(p2));
            line02.Layer = additionalline;
            dxf.AddEntity(line02);

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p2s));
            poly11.Vertexes[0].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p2e));
            poly11.Vertexes.Add(new LwPolylineVertex(p3s));
            poly11.Vertexes[2].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p3e));
            poly11.Vertexes.Add(new LwPolylineVertex(p4s));
            poly11.Vertexes[4].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p4e));
            poly11.Vertexes.Add(new LwPolylineVertex(p5s));
            poly11.Vertexes[6].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p5e));
            poly11.Vertexes.Add(new LwPolylineVertex(p6s));
            poly11.Vertexes[8].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6e));
            poly11.Vertexes.Add(new LwPolylineVertex(p7s));
            poly11.Vertexes[10].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p7e));
            poly11.Vertexes.Add(new LwPolylineVertex(p8s));
            poly11.Vertexes[12].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8e));
            poly11.Vertexes.Add(new LwPolylineVertex(p9s));
            poly11.Vertexes[14].Bulge = Math.Tan(45 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p9e));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);


            Vector2 p20 = fun.Polar(p0, 0, 3 * ic);
            Vector2 p21 = new Vector2(p20.X, p6.Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));

            inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            cenline1.Linetype = Linetype.Center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic / 2 + 2), fun.Polar(p0, -pi / 2, ic / 2 + 2));
            cenline2.Layer = center;
            cenline2.Linetype = Linetype.Center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);

            fun.jz(dxf, fun.Polar(fun.Polar(p0, pi / 2, ic / 2), 180 * pi / 180, offset + ic / 2), 90, 3, "A");
            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + ic / 2, 90, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p2, p3), offset, 180, dimensionStyle);
                dim2.UserText = "LE";
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = "S";
                dxf.AddEntity(dim3);

                RadialDimension dim5 = new RadialDimension(arc6, 90, offset, dimensionStyle);
                dim5.UserText = "RE";
                dxf.AddEntity(dim5);
                /*
                Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p6, fun.Polar(p6, 0, 0.1)), new Line(p6, fun.Polar(p6, pi - ang3, 0.1)), offset, dimensionStyle);
                dim6.UserText = "EPSR";
                dxf.AddEntity(dim6);*/


                fun.jdbz2(dxf, new Line(p6, fun.Polar(p6, 0, 0.1)), new Line(p6, fun.Polar(p6, pi - ang3, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");


            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + ic / 2, 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset + ic / 2, 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim3);
                }
                if (stc != 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim3);
                }
                /*
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -pi / 2, ic / 2)), offset+ic/2, 90, dimensionStyle);
                dim1.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim3);
                */
                LinearDimension dim2 = new LinearDimension(new Line(p2, p3), offset, 180, dimensionStyle);
                dim2.UserText = String.Format("LE={0}", Math.Round(le / scale, 2));
                dxf.AddEntity(dim2);

                RadialDimension dim5 = new RadialDimension(arc6, 90, offset, dimensionStyle);
                dim5.UserText = String.Format("RE={0}", re / scale);
                dxf.AddEntity(dim5);
                /*
                Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p6, fun.Polar(p6, 0, 0.1)), new Line(p6, fun.Polar(p6, pi - ang3, 0.1)), offset, dimensionStyle);
                dim6.UserText = String.Format("EPSR={0}°", epsr/(pi/180));
                dxf.AddEntity(dim6);*/

                fun.jdbz2(dxf, new Line(p6, fun.Polar(p6, 0, 0.1)), new Line(p6, fun.Polar(p6, pi - ang3, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");

            }
            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ParallelogramInsert(Dictionary<string, Object> data)    //不等边四边形刀片，适用于L,A,B,K等型刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;

            double tic = Convert.ToDouble(data["w1"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double l = Convert.ToDouble(data["l"]) * scale;
            double w1 = Convert.ToDouble(data["w1"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);

            double insl = l / Math.Sin(epsr);
            double ang1 = pi / 2 - epsr;
            double ang2 = pi - epsr;

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p2 = fun.Polar(p1, 0, l);
            Vector2 p3 = fun.Polar(p2, epsr, w1 / Math.Sin(epsr));
            Vector2 p4 = fun.Polar(p3, pi, l);
            Vector2 p0 = fun.Inters(p1, p3, p2, p4);


            double ang3 = fun.CalAngle(p1, p3);
            double ang4 = epsr - ang3;
            double ang5 = pi - fun.CalAngle(p2, p4);
            double ang6 = ang3 - ang5;
            double ang7 = epsr / 2;
            double ang8 = ang2 / 2;

            Vector2 p1p = fun.Polar(p1, ang7, re / Math.Sin(ang7));
            Vector2 p2p = fun.Polar(p2, pi - ang8, re / Math.Sin(ang8));
            Vector2 p3p = fun.Polar(p3, pi + ang7, re / Math.Sin(ang7));
            Vector2 p4p = fun.Polar(p4, -ang8, re / Math.Sin(ang8));
            Vector2 p5 = fun.Polar(p1, epsr, re / Math.Tan(ang7));
            Vector2 p6 = fun.Polar(p1, 0, re / Math.Tan(ang7));
            Vector2 p7 = fun.Polar(p2, pi, re / Math.Tan(ang8));
            Vector2 p8 = fun.Polar(p2, epsr, re / Math.Tan(ang8));
            Vector2 p9 = fun.Polar(p3, pi + epsr, re / Math.Tan(ang7));
            Vector2 p10 = fun.Polar(p3, pi, re / Math.Tan(ang7));
            Vector2 p11 = fun.Polar(p4, 0, re / Math.Tan(ang8));
            Vector2 p12 = fun.Polar(p4, pi + epsr, re / Math.Tan(ang8));
            Vector2 p20 = fun.Polar(p0, 0, 2 * l);
            Vector2 p21 = new Vector2(p20.X, p3.Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));






            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes[2].Bulge = Math.Tan(90 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes[4].Bulge = Math.Tan(90 * pi / 180 / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[6].Bulge = Math.Tan(90 * pi / 180 / 4);
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);

            Line line1 = new Line(p6, p7);
            Line line2 = new Line(p8, p9);
            Line line3 = new Line(p10, p11);
            Line line4 = new Line(p12, p5);
            Arc arc1 = fun.DrawArc(p5, p1p, p6);
            Arc arc2 = fun.DrawArc(p7, p2p, p8);
            Arc arc3 = fun.DrawArc(p9, p3p, p10);
            Arc arc4 = fun.DrawArc(p11, p4p, p12);
            Circle circle1 = new Circle(p0, d1 / 2);
            circle1.Layer = contour;
            dxf.AddEntity(circle1);

            Line cenline1 = new Line(fun.Polar(p0, pi, l / 2 + 0.5), fun.Polar(p0, 0, l / 2 + 0.5));
            cenline1.Layer = center;
            dxf.AddEntity(cenline1);
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, w1 / 2 + 0.5), fun.Polar(p0, -0.5 * pi, w1 / 2 + 0.5));
            cenline2.Layer = center;
            dxf.AddEntity(cenline2);
            Line cenline3 = new Line(fun.Polar(p20, 0, 0.5), fun.Polar(p20, pi, s + 0.5));
            cenline3.Layer = center;
            dxf.AddEntity(cenline3);

            inserthole(dxf, p0, p20, p21, p20, p21, scale, data);

            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textheight;
            double offset = 10;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim1.UserText = "L";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p1, p4), offset, 90, dimensionStyle);
                dim2.UserText = "W1";
                dxf.AddEntity(dim2);

                LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim3.UserText = "S";
                dxf.AddEntity(dim3);

                RadialDimension dim5 = new RadialDimension(arc4, 90, offset, dimensionStyle);
                dim5.UserText = "RE";
                dxf.AddEntity(dim5);

                Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, 0, 0.1)), new Line(p3, fun.Polar(p3, epsr, 0.1)), offset, dimensionStyle);
                dim6.UserText = "EPSR";
                dxf.AddEntity(dim6);


                fun.jdbz2(dxf, new Line(p3, fun.Polar(p3, 0, 0.1)), new Line(p3, fun.Polar(p3, epsr, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");

            }
            else
            {
                LinearDimension dim1 = new LinearDimension(new Line(p1, p2), offset, 180, dimensionStyle);
                dim1.UserText = String.Format("L={0}", l / scale);
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p1, p4), offset, 90, dimensionStyle);
                dim2.UserText = String.Format("W1={0}", w1 / scale);
                dxf.AddEntity(dim2);

                if (stc == 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim3);
                }
                if (stc != 0)
                {
                    LinearDimension dim3 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim3.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim3);
                }

                RadialDimension dim5 = new RadialDimension(arc4, 90, offset, dimensionStyle);
                dim5.UserText = String.Format("RE={0}", re / scale);
                dxf.AddEntity(dim5);

                /*  Angular2LineDimension dim6 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, 0, 0.1)), new Line(p3, fun.Polar(p3, epsr, 0.1)), offset, dimensionStyle);
                  dim6.UserText = String.Format("EPSR={0}°", epsr/(pi/180));
                  dxf.AddEntity(dim6);*/


                fun.jdbz2(dxf, new Line(p3, fun.Polar(p3, 0, 0.1)), new Line(p3, fun.Polar(p3, epsr, 0.1)), offset, textheight, textheight, 0.4, "EPSR=" + epsr / (pi / 180) + "°", "", "");

            }

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TriangularInsert1(Dictionary<string, Object> data)    //带修光刃正三边形刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;
            double offset = 10;


            double scale = Convert.ToDouble(data["scale"]); //放大系数
            double tic = Convert.ToDouble(data["ic"]);
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }


            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;

            double IC = Convert.ToDouble(data["ic"]) * scale;
            double S = Convert.ToDouble(data["s"]) * scale;
            double L = Convert.ToDouble(data["l"]) * scale;
            double M = Convert.ToDouble(data["m"]) * scale;
            double BS = Convert.ToDouble(data["bs"]) * scale;
            double EPSR = Convert.ToDouble(data["epsr"]);
            double KRINS = Convert.ToDouble(data["krins"]);
            double KCH = EPSR / 2;
            double AN = Convert.ToDouble(data["an"]);
            double BCH = Convert.ToDouble(data["bch"]) * scale;
            double AS = Convert.ToDouble(data["as"]);
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);

            double AS_1 = AS * (Math.PI / 180);
            double KCH_1 = KCH * (Math.PI / 180);
            double EPSR_1 = EPSR * (Math.PI / 180);
            double KRINS_1 = KRINS * (Math.PI / 180);
            double EPSRN = EPSR / 2 * (Math.PI / 180);
            double An_1 = AN * (Math.PI / 180);



            Vector2 p1 = new Vector2(0, 0);
            Vector2 p2 = new Vector2((BCH * (Math.Cos(90 - KRINS)) + BS * (Math.Sin(KCH_1))) / Math.Tan(EPSR_1), BCH * (Math.Cos(90 - KRINS)) + BS * (Math.Sin(KCH_1)));
            Vector2 p3 = new Vector2(p2.X + BCH * (Math.Cos(KRINS_1)), p2.Y - BCH * (Math.Cos(90 - KRINS)));

            Vector2 p4 = new Vector2(p3.X + (BS * Math.Cos(KCH_1)), p1.Y);
            Vector2 p5 = new Vector2(IC / Math.Tan(EPSR_1 / 2), p1.Y);
            Vector2 p6 = new Vector2((IC / 2) / Math.Tan(EPSR_1 / 2), IC / Math.Tan(EPSR_1 / 2) * Math.Sin(EPSR_1));
            Vector2 p7 = new Vector2(p6.X, IC / 2);

            double length1 = fun.CalDistance(p1, p2);
            double length2 = fun.CalDistance(p1, p3);
            double length3 = fun.CalDistance(p1, p4);
            Vector2 p8 = new Vector2(p6.X - Math.Sin(EPSRN) * length1, p6.Y - Math.Cos(EPSRN) * length1);
            Vector2 p9 = new Vector2(p6.X, p6.Y - length2);
            Vector2 p10 = new Vector2(p6.X + Math.Sin(EPSRN) * length1, p8.Y);
            Vector2 p11 = new Vector2(p5.X - Math.Cos(EPSR_1) * length1, p5.Y + Math.Sin(EPSR_1) * length1);
            Vector2 p12 = new Vector2(p11.X, p11.Y - BCH);
            Vector2 p13 = new Vector2(p5.X - length3, p5.Y);

            Vector2 p14 = new Vector2(p5.X + 6 * S, p5.Y);
            Vector2 p15 = new Vector2(p14.X, p9.Y);
            Vector2 p16 = new Vector2(p15.X - S, p15.Y - S * Math.Tan(An_1));
            Vector2 p17 = new Vector2(p14.X - S, p14.Y + S * Math.Tan(An_1));

            Vector2 p18 = new Vector2(p17.X - 2 * S, p17.Y + 8);
            Vector2 p19 = new Vector2(p18.X - 2 * BS * Math.Sin(KCH_1), p18.Y + 2 * BS * Math.Cos(KCH_1));
            Vector2 p20 = new Vector2(p19.X - S * Math.Cos(KCH_1), p19.Y - S * Math.Sin(KCH_1));
            Vector2 p21 = new Vector2(p20.X + 2 * BS * Math.Sin(KCH_1), p20.Y - 2 * BS * Math.Cos(KCH_1));

            Vector2 p22 = new Vector2(p7.X - IC / 2, p7.Y);
            Vector2 p23 = new Vector2(p7.X + IC / 2, p7.Y);
            Vector2 p24 = new Vector2(p13.X, p13.Y - 3);
            Vector2 p25 = new Vector2(p14.X - 4, p14.Y);

            Vector2 p26 = new Vector2(p1.X - 2.87, p1.Y - 4);
            Vector2 p27 = new Vector2(p7.X + IC * Math.Cos(KCH_1), p7.Y - IC * Math.Sin(KCH_1));
            Vector2 p28 = new Vector2(p12.X, p12.Y + 10);

            double angular2 = fun.CalAngle(p11, p12);


            Vector2[] Line1 = { p2, p3 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { p4, p3 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line3 = { p2, p8 };
            fun.drawBLine(dxf, Line3, 0.3, contour);

            Vector2[] Line7 = { p8, p9 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { p10, p9 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line9 = { p11, p12 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line10 = { p12, p13 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { p4, p13 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { p10, p11 };
            fun.drawBLine(dxf, Line12, 0.3, contour);


            LwPolyline Arc00 = new LwPolyline();
            Arc00.Vertexes.Add(new LwPolylineVertex(p1));
            Arc00.Vertexes.Add(new LwPolylineVertex(p5));
            Arc00.Vertexes.Add(new LwPolylineVertex(p6));
            Arc00.Vertexes.Add(new LwPolylineVertex(p1));
            Arc00.Layer = additionalline;
            dxf.AddEntity(Arc00);

            /*
            Vector2[] Line13 = { p6, p8 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { p6, p10 };
           fun.drawBLine(dxf, Line14, 0.3, contour);
 
            Vector2[] Line5 = { p5, p11 };
          fun.drawBLine(dxf, Line5, 0.3, contour);
            Vector2[] Line6 = { p5, p13 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line4 = { p1, p2 };
           fun.drawBLine(dxf, Line4, 0.3, contour);
           Vector2[] Line16= { p1, p4 };
           fun.drawBLine(dxf, Line4, 0.3, contour);*/
            Vector2[] Line17 = { p14, p17 };
            fun.drawBLine(dxf, Line17, 0.3, contour);

            Vector2[] Line18 = { p16, p17 };
            fun.drawBLine(dxf, Line18, 0.3, contour);
            Vector2[] Line19 = { p16, p15 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { p14, p15 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            Vector2[] Line21 = { p18, p19 };
            fun.drawBLine(dxf, Line21, 0.3, contour);
            Vector2[] Line22 = { p18, p21 };
            fun.drawBLine(dxf, Line22, 0.3, contour);
            Vector2[] Line23 = { p20, p21 };
            fun.drawBLine(dxf, Line23, 0.3, contour);



            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p15));
            poly1.Vertexes.Add(new LwPolylineVertex(p16));
            poly1.Vertexes.Add(new LwPolylineVertex(p17));
            poly1.Vertexes.Add(new LwPolylineVertex(p14));

            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.5, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);

            Circle circle00 = new Circle(p7, IC / 2);
            circle00.Layer = center;
            dxf.AddEntity(circle00);

            List<Vector3> points00 = new List<Vector3>
           {
                 new Vector3(p20.X,p20.Y , 0),
                new Vector3(p20.X+0.3,p20.Y+0.3, 0),
                new Vector3(p20.X+1.5,p20.Y+0.5, 0),
                new Vector3(p20.X+2.5,p20.Y+1.5, 0),
                  new Vector3(p19.X,p19.Y, 0),



            };

            Spline spline00 = new Spline(points00);
            spline00.Layer = contour;
            DxfDocument doc00 = new DxfDocument();
            dxf.AddEntity(spline00);

            DimensionStyle dimensionStyle = fun.DimStyle(true);//内箭头
            DimensionStyle dimensionStyle2 = fun.DimStyle(false);//外箭头


            //线段尺寸标注
            //尺寸1

            LinearDimension dim1 = new LinearDimension(new Line(p1, p6), offset, 60, dimensionStyle);
            dim1.UserText = "l";
            dxf.AddEntity(dim1);

            LinearDimension dim2 = new LinearDimension(new Line(p22, p23), 0, 0, dimensionStyle);
            dim2.UserText = "d";
            dxf.AddEntity(dim2);
            LinearDimension dim3 = new LinearDimension(new Line(p11, p23), offset, 0, dimensionStyle);
            dim3.SetDimensionLinePosition(new Vector2(p23.X + 1, p23.Y));
            dim3.UserText = "m";
            dxf.AddEntity(dim3);

            LinearDimension dim4 = new LinearDimension(new Line(p11, p12), offset, 270, dimensionStyle2);
            dim4.UserText = "bs";
            dxf.AddEntity(dim4);
            LinearDimension dim5 = new LinearDimension(new Line(p13, p12), offset, 200, dimensionStyle2);
            dim5.UserText = "bs";
            dxf.AddEntity(dim5);
            LinearDimension dim6 = new LinearDimension(new Line(p15, p16), offset, 360, dimensionStyle);
            dim6.UserText = "S";
            dxf.AddEntity(dim6);
            LinearDimension dim7 = new LinearDimension(new Line(p13, p27), offset, 125, dimensionStyle2);
            dim7.UserText = "m";
            dxf.AddEntity(dim7);


            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p5, p11), new Line(p5, p13), offset * 2, dimensionStyle);
            angdim1.UserText = "εr";
            dxf.AddEntity(angdim1);

            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(p13, p1), new Line(p13, p24), offset * 2, dimensionStyle);
            angdim2.UserText = "xr=90°";
            dxf.AddEntity(angdim2);
            if (AN == 11)

            {
                Angular2LineDimension angdim4 = new Angular2LineDimension(new Line(p14, p17), new Line(p14, p25), offset * 4, dimensionStyle2);
                angdim4.UserText = "11°±1′";
                dxf.AddEntity(angdim4);
            }
            if (AN == 20)
            {
                Angular2LineDimension angdim4 = new Angular2LineDimension(new Line(p14, p17), new Line(p14, p25), offset * 4, dimensionStyle2);
                angdim4.UserText = "20°±30′";
                dxf.AddEntity(angdim4);
            }


            if (AS == 11)
            {
                Angular2LineDimension angdim5 = new Angular2LineDimension(new Line(p18, p19), new Line(p18, p21), offset, dimensionStyle);
                angdim5.UserText = "11°±30′";
                dxf.AddEntity(angdim5);
            }
            if (AS == 20)
            {
                Angular2LineDimension angdim5 = new Angular2LineDimension(new Line(p18, p19), new Line(p18, p21), offset, dimensionStyle);
                angdim5.UserText = "20°±1′";
                dxf.AddEntity(angdim5);
            }
            if (AS == 15)
            {
                Angular2LineDimension angdim5 = new Angular2LineDimension(new Line(p18, p19), new Line(p18, p21), offset, dimensionStyle);
                angdim5.UserText = "15°±1′";
                dxf.AddEntity(angdim5);
            }
            Angular2LineDimension angdim3 = new Angular2LineDimension(new Line(p26, p8), new Line(p26, p12), 2 * offset, dimensionStyle);
            angdim3.UserText = "φ";
            dxf.AddEntity(angdim3);

            //Angular2LineDimension angdim6 = new Angular2LineDimension(new Line(p26, p8), new Line(p26, p12), offset + 17, dimensionStyle);
            //angdim6.UserText = "φ";
            //dxf.AddEntity(angdim6);
            //Angular2LineDimension angdim7 = new Angular2LineDimension(new Line(p28, p1), new Line(p28, p12), offset + 17, dimensionStyle);
            //angdim7.UserText = "φ";
            //dxf.AddEntity(angdim7);


            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p1.X - 1189 / 2.0, p1.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p1.X - 841 / 2.0, p1.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p1.X - 594 / 2.0, p1.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p1.X - 420 / 2.0, p1.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p1.X - 297 / 2.0, p1.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p1.X - 210 / 2.0, p1.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], textheight, 0, 0.6, "C");
                }
            }


            fun.SetLayer(dxf); fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);




        }

        public static void RhombicInsert1(Dictionary<string, Object> data)    //修光刃正方形刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数


            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }

            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;

            double IC = Convert.ToDouble(data["ic"]);
            double S = Convert.ToDouble(data["s"]) * scale;
            double L = IC;
            double M = Convert.ToDouble(data["m"]);
            double BS = Convert.ToDouble(data["bs"]);
            double EPSR = Convert.ToDouble(data["epsr"]);
            double KRINS = Convert.ToDouble(data["krins"]);
            double KCH = Convert.ToDouble(data["kch"]);
            double AN = Convert.ToDouble(data["an"]);
            double BCH = Convert.ToDouble(data["bch"]);
            double AS = Convert.ToDouble(data["as"]);

            //double IC   = 10;
            //double S    = 10;
            //double L    = 10;
            //double M    = 10;
            //double BS   = 10;
            //double EPSR = 10;
            //double KRINS =10;
            //double KCH  = 10;
            //double AN   = 10;
            //double BCH  = 10;
            //double AS = 10;


            //double EPSRN = 75 * (Math.PI / 180);

            double AS_1 = AS * (Math.PI / 180);

            double EPSR_1 = EPSR * (Math.PI / 180);
            double KRINS_1 = KRINS * (Math.PI / 180);

            double An_1 = AN * (Math.PI / 180);
            double KCH_1 = KCH * (Math.PI / 180);




            DimensionStyle dimensionStyle = new DimensionStyle("ds");
            dimensionStyle.ArrowSize = textheight;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = textheight;
            double offset = 3;
            dimensionStyle.ExtLineExtend = 0.2;//标注延长线长度/2

            if (KRINS == 75 && AN == 0)
            {


                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));
                Vector2 v4 = new Vector2(v3.X - (BS * Math.Sin(EPSR_1 - KRINS_1)), v3.Y + (BS * Math.Cos(EPSR_1 - KRINS_1)));
                double length1 = fun.CalDistance(v1, v4);

                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.3, contour);


                Vector2[] Line2 = { v2, v3 };
                fun.drawBLine(dxf, Line2, 0.3, contour);
                Vector2[] Line3 = { v3, v4 };
                fun.drawBLine(dxf, Line3, 0.3, contour);

                Vector2 v18 = new Vector2(v4.X, v1.Y + L / 2);
                Vector2 v19 = new Vector2(v18.X + L, v18.Y);
                Vector2 v20 = new Vector2(v4.X + L / 2, v1.X + L);
                Vector2 v21 = new Vector2(v20.X, v20.Y - L);
                Vector2 v22 = new Vector2(v4.X, v1.Y + L);
                Vector2 v23 = new Vector2(v4.X + L, v1.Y);



                Line Line4 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsl1 = { new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y), new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y) };
                fun.drawBLine(dxf, lsl1, 0.3, contour);
                Line Line5 = fun.mirrorline(new Line(v2, v3), v18, v19);
                Vector2[] lsl2 = { new Vector2(Line5.StartPoint.X, Line5.StartPoint.Y), new Vector2(Line5.EndPoint.X, Line5.EndPoint.Y) };
                fun.drawBLine(dxf, lsl2, 0.3, contour);
                Line Line6 = fun.mirrorline(new Line(v4, v3), v18, v19);
                Vector2[] lsl3 = { new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y), new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y) };
                fun.drawBLine(dxf, lsl3, 0.3, contour);


                Line Line7 = fun.mirrorline(new Line(v1, v2), v22, v23);
                Vector2[] lsl4 = { new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y), new Vector2(Line7.EndPoint.X, Line7.EndPoint.Y) };
                fun.drawBLine(dxf, lsl4, 0.3, contour);
                Line Line8 = fun.mirrorline(new Line(v3, v2), v22, v23);
                Vector2[] lsl5 = { new Vector2(Line8.StartPoint.X, Line8.StartPoint.Y), new Vector2(Line8.EndPoint.X, Line8.EndPoint.Y) };
                fun.drawBLine(dxf, lsl5, 0.3, contour);
                Line Line9 = fun.mirrorline(new Line(v3, v4), v22, v23);
                Vector2[] lsl6 = { new Vector2(Line9.StartPoint.X, Line9.StartPoint.Y), new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y) };
                fun.drawBLine(dxf, lsl6, 0.3, contour);

                Line Line10 = fun.mirrorline(new Line(v1, v2), v20, v21);
                Vector2[] lsl7 = { new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y), new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y) };
                fun.drawBLine(dxf, lsl7, 0.3, contour);
                Line Line11 = fun.mirrorline(new Line(v3, v2), v20, v21);
                Vector2[] lsl8 = { new Vector2(Line11.StartPoint.X, Line11.StartPoint.Y), new Vector2(Line11.EndPoint.X, Line11.EndPoint.Y) };
                fun.drawBLine(dxf, lsl8, 0.3, contour);
                Line Line12 = fun.mirrorline(new Line(v3, v4), v20, v21);
                Vector2[] lsL9 = { new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y), new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y) };
                fun.drawBLine(dxf, lsL9, 0.3, contour);

                Vector2 v5 = new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y);
                Vector2[] Line13 = { v4, v5 };
                fun.drawBLine(dxf, Line13, 0.3, contour);

                Vector2 v6 = new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y);
                Vector2 v7 = new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y);

                Vector2 v8 = new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y);
                Vector2 v9 = new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y);

                Vector2 v10 = new Vector2(Line9.StartPoint.X, Line9.StartPoint.X);
                Vector2 v11 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v14 = new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y);
                Vector2 v15 = new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y);

                Vector2[] Line14 = { v8, v9 };
                fun.drawBLine(dxf, Line14, 0.3, contour);

                Vector2 v12 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v13 = new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y);
                Vector2[] Line15 = { v13, v12 };
                fun.drawBLine(dxf, Line15, 0.3, contour);

                Vector2 v16 = new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y);
                Vector2[] Line16 = { v1, v16 };
                fun.drawBLine(dxf, Line16, 0.3, contour);


                Vector2 v17 = new Vector2(v21.X, v21.Y + L / 2);

                Circle circle00 = new Circle(v17, IC / 2);
                circle00.Layer = center;
                dxf.AddEntity(circle00);


                Vector2 v24 = new Vector2(v23.X + L, v1.Y);
                Vector2 v25 = new Vector2(v24.X, v2.Y);
                Vector2 v26 = new Vector2(v24.X, v3.Y);
                Vector2 v27 = new Vector2(v24.X, v4.Y);
                Vector2 v28 = new Vector2(v24.X, v5.Y);
                Vector2 v29 = new Vector2(v24.X, v6.Y);
                Vector2 v30 = new Vector2(v24.X, v7.Y);
                Vector2 v31 = new Vector2(v24.X, v8.Y);
                Vector2 v32 = new Vector2(v31.X + S, v31.Y);
                Vector2 v33 = new Vector2(v32.X, v30.Y);
                Vector2 v34 = new Vector2(v32.X, v29.Y);
                Vector2 v35 = new Vector2(v32.X, v28.Y);
                Vector2 v36 = new Vector2(v32.X, v27.Y);
                Vector2 v37 = new Vector2(v32.X, v26.Y);
                Vector2 v38 = new Vector2(v32.X, v25.Y);
                Vector2 v39 = new Vector2(v32.X, v24.Y);

                Vector2 v40 = new Vector2(v2.X, v1.Y);
                Vector2 v41 = new Vector2(v2.X + v2.Y / Math.Tan(EPSR_1 / 2), v1.Y);

                Vector2 v42 = new Vector2(v15.X + 1.16, v15.Y + 0.3);
                Vector2 v43 = new Vector2(v15.X + 6.09, v15.Y + 4.62);
                Vector2 v44 = new Vector2(v16.X + 1.99, v16.Y);
                Vector2 v45 = new Vector2(v44.X - 0.95, v44.Y - 3.98);



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v31));
                poly1.Vertexes.Add(new LwPolylineVertex(v32));
                poly1.Vertexes.Add(new LwPolylineVertex(v39));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);


                Vector2[] line18 = { v26, v37 };
                fun.drawBLine(dxf, line18, 0.3, contour);

                Vector2[] line20 = { v29, v34 };
                fun.drawBLine(dxf, line20, 0.3, contour);

                Vector2[] line22 = { v31, v32 };
                fun.drawBLine(dxf, line22, 0.3, contour);
                Vector2[] Line17 = { v25, v38 };
                fun.drawBLine(dxf, Line17, 0.3, contour);
                Vector2[] line19 = { v28, v35 };
                fun.drawBLine(dxf, line19, 0.3, contour);
                Vector2[] line21 = { v30, v33 };
                fun.drawBLine(dxf, line21, 0.3, contour);
                Vector2[] line23 = { v27, v36 };
                fun.drawBLine(dxf, line23, 0.3, contour);

                LinearDimension dim9 = new LinearDimension(new Line(v3, v2), offset, 134, dimensionStyle);
                dim9.UserText = "≈1";
                dxf.AddEntity(dim9);
                Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(v41, v40), new Line(v41, v3), offset + 2, dimensionStyle);
                angdim2.UserText = "45°";
                dxf.AddEntity(angdim2);
                LinearDimension dim7 = new LinearDimension(new Line(v15, v16), offset, 165, dimensionStyle);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);
                LinearDimension dim8 = new LinearDimension(new Line(v13, v14), offset, 260, dimensionStyle);
                dim8.UserText = "bs";
                dxf.AddEntity(dim8);
                LinearDimension dim4 = new LinearDimension(new Line(v19, v13), offset, -19, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);


                fun.jdbz1(dxf, new Line(v13, v14), new Line(v9, v7), offset + 20, "φ", textheight);
                fun.jdbz1(dxf, new Line(v44, v1), new Line(v44, v45), offset + 2, "xr＝75°", textheight);
                fun.jdbz1(dxf, new Line(v22, v12), new Line(v42, v43), offset + 2, "xr＝75°", textheight);






                //线段尺寸标注
                //尺寸1
                LinearDimension dim1 = new LinearDimension(new Line(v5, v12), offset + 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v8), offset + 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v18, v19), offset - 3, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);

                LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                dim5.UserText = "m";
                dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v24, v39), offset + 2, 180, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);



                //Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(v23, v19), new Line(v23, v21), offset + 3, dimensionStyle);
                //angdim1.UserText = "εr";
                ///   dxf.AddEntity(angdim1);

                fun.jdbz1(dxf, new Line(v23, v19), new Line(v23, v21), offset + 3, "εr", textheight);
                fun.jdbz1(dxf, new Line(v16, v15), new Line(v4, v5), offset + 20, "φ", textheight);





            }



            if (KRINS == 45 && AN == 0)
            {

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));
                Vector2 v4 = new Vector2(v3.X - (BS * Math.Sin(EPSR_1 - KRINS_1)), v3.Y + (BS * Math.Cos(EPSR_1 - KRINS_1)));
                double length1 = fun.CalDistance(v1, v4);






                Vector2 v18 = new Vector2(v4.X, v1.Y + L / 2);
                Vector2 v19 = new Vector2(v18.X + L, v18.Y);
                Vector2 v20 = new Vector2(v4.X + L / 2, v1.X + L);
                Vector2 v21 = new Vector2(v20.X, v20.Y - L);
                Vector2 v22 = new Vector2(v4.X, v1.Y + L);
                Vector2 v23 = new Vector2(v4.X + L, v1.Y);



                Line Line4 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsl1 = { new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y), new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y) };
                ;
                Line Line5 = fun.mirrorline(new Line(v2, v3), v18, v19);
                Vector2[] lsl2 = { new Vector2(Line5.StartPoint.X, Line5.StartPoint.Y), new Vector2(Line5.EndPoint.X, Line5.EndPoint.Y) };
                ;
                Line Line6 = fun.mirrorline(new Line(v4, v3), v18, v19);
                Vector2[] lsl3 = { new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y), new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y) };



                Line Line7 = fun.mirrorline(new Line(v1, v2), v22, v23);
                Vector2[] lsl4 = { new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y), new Vector2(Line7.EndPoint.X, Line7.EndPoint.Y) };

                Line Line8 = fun.mirrorline(new Line(v3, v2), v22, v23);
                Vector2[] lsl5 = { new Vector2(Line8.StartPoint.X, Line8.StartPoint.Y), new Vector2(Line8.EndPoint.X, Line8.EndPoint.Y) };
                ;
                Line Line9 = fun.mirrorline(new Line(v3, v4), v22, v23);
                Vector2[] lsl6 = { new Vector2(Line9.StartPoint.X, Line9.StartPoint.Y), new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y) };


                Line Line10 = fun.mirrorline(new Line(v1, v2), v20, v21);
                Vector2[] lsl7 = { new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y), new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y) };

                Line Line11 = fun.mirrorline(new Line(v3, v2), v20, v21);
                Vector2[] lsl8 = { new Vector2(Line11.StartPoint.X, Line11.StartPoint.Y), new Vector2(Line11.EndPoint.X, Line11.EndPoint.Y) };

                Line Line12 = fun.mirrorline(new Line(v3, v4), v20, v21);
                Vector2[] lsL9 = { new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y), new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y) };


                Vector2 v5 = new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y);
                Vector2[] Line13 = { v4, v5 };
                fun.drawBLine(dxf, Line13, 0.3, contour);

                Vector2 v6 = new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y);
                Vector2 v7 = new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y);

                Vector2 v8 = new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y);
                Vector2 v9 = new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y);

                Vector2 v10 = new Vector2(Line9.StartPoint.X, Line9.StartPoint.X);
                Vector2 v11 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v14 = new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y);
                Vector2 v15 = new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y);

                Vector2[] Line14 = { v8, v9 };
                fun.drawBLine(dxf, Line14, 0.3, contour);

                Vector2 v12 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v13 = new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y);
                Vector2[] Line15 = { v13, v12 };
                fun.drawBLine(dxf, Line15, 0.3, contour);

                Vector2 v16 = new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y);
                Vector2[] Line16 = { v1, v16 };
                fun.drawBLine(dxf, Line16, 0.3, contour);



                Vector2 v17 = new Vector2(v21.X, v21.Y + L / 2);


                Vector2[] line24 = { v5, v8 };
                fun.drawBLine(dxf, line24, 0.3, contour);
                Vector2[] line25 = { v9, v12 };
                fun.drawBLine(dxf, line25, 0.3, contour);
                Vector2[] line26 = { v13, v16 };
                fun.drawBLine(dxf, line26, 0.3, contour);
                Vector2[] line27 = { v4, v1 };
                fun.drawBLine(dxf, line27, 0.3, contour);

                Circle circle00 = new Circle(v17, IC / 2);
                circle00.Layer = center;
                dxf.AddEntity(circle00);


                Vector2 v24 = new Vector2(v23.X + L, v1.Y);
                Vector2 v25 = new Vector2(v24.X, v2.Y);
                Vector2 v26 = new Vector2(v24.X, v3.Y);
                Vector2 v27 = new Vector2(v24.X, v4.Y);
                Vector2 v28 = new Vector2(v24.X, v5.Y);
                Vector2 v29 = new Vector2(v24.X, v6.Y);
                Vector2 v30 = new Vector2(v24.X, v7.Y);
                Vector2 v31 = new Vector2(v24.X, v8.Y);
                Vector2 v32 = new Vector2(v31.X + S, v31.Y);
                Vector2 v33 = new Vector2(v32.X, v30.Y);
                Vector2 v34 = new Vector2(v32.X, v29.Y);
                Vector2 v35 = new Vector2(v32.X, v28.Y);
                Vector2 v36 = new Vector2(v32.X, v27.Y);
                Vector2 v37 = new Vector2(v32.X, v26.Y);
                Vector2 v38 = new Vector2(v32.X, v25.Y);
                Vector2 v39 = new Vector2(v32.X, v24.Y);

                Vector2 v40 = new Vector2(v2.X, v1.Y);
                Vector2 v41 = new Vector2(v2.X + v2.Y / Math.Tan(EPSR_1 / 2), v1.Y);

                Vector2 v42 = new Vector2(v15.X + 1.16, v15.Y + 0.3);
                Vector2 v43 = new Vector2(v15.X + 6.09, v15.Y + 4.62);
                Vector2 v44 = new Vector2(v16.X + 1.99, v16.Y);
                Vector2 v45 = new Vector2(v44.X - 0.95, v44.Y - 3.98);



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v31));
                poly1.Vertexes.Add(new LwPolylineVertex(v32));
                poly1.Vertexes.Add(new LwPolylineVertex(v39));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                Vector2[] line18 = { v26, v37 };
                fun.drawBLine(dxf, line18, 0.5, contour);

                Vector2[] line20 = { v29, v34 };
                fun.drawBLine(dxf, line20, 0.5, contour);

                fun.jdbz1(dxf, new Line(v42, v12), new Line(v42, v43), offset + 2, "xr＝45°", textheight);



                //线段尺寸标注
                //尺寸1
                LinearDimension dim1 = new LinearDimension(new Line(v5, v12), offset + 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v8), offset + 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v18, v19), offset - 3, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);

                LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                dim5.UserText = "m";
                dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v24, v39), offset + 2, 180, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);

                fun.jdbz1(dxf, new Line(v23, v19), new Line(v23, v21), offset + 3, "εr", textheight);
                fun.jdbz1(dxf, new Line(v16, v15), new Line(v4, v5), offset + 25, "φ", textheight);








            }

            if (KRINS != 0 && AN == 11)
            {
                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));

                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.3, contour);

                Vector2[] Line2 = { v3, v2 };
                fun.drawBLine(dxf, Line2, 0.3, contour);

                Vector2 v14 = new Vector2(v3.X, v1.Y + L / 2);
                Vector2 v15 = new Vector2(v14.X + L, v14.Y);
                Vector2 v16 = new Vector2(v14.X + L / 2, v1.Y + L);
                Vector2 v17 = new Vector2(v16.X, v16.Y - L);
                Vector2 v13 = new Vector2(v14.X + L / 2, v14.Y);
                Vector2 v18 = new Vector2(v3.X, v1.Y + L);
                Vector2 v19 = new Vector2(v3.X + L, v1.Y);


                Line line3 = fun.mirrorline(new Line(v1, v2), v14, v15);
                Vector2[] lsline1 = { new Vector2(line3.StartPoint.X, line3.StartPoint.Y), new Vector2(line3.EndPoint.X, line3.EndPoint.Y) };
                fun.drawBLine(dxf, lsline1, 0.3, contour);
                Line line4 = fun.mirrorline(new Line(v2, v3), v14, v15);
                Vector2[] lsline2 = { new Vector2(line4.StartPoint.X, line4.StartPoint.Y), new Vector2(line4.EndPoint.X, line4.EndPoint.Y) };
                fun.drawBLine(dxf, lsline2, 0.3, contour);


                Line line5 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsline4 = { new Vector2(line5.StartPoint.X, line5.StartPoint.Y), new Vector2(line5.EndPoint.X, line5.EndPoint.Y) };
                fun.drawBLine(dxf, lsline4, 0.3, contour);
                Line line6 = fun.mirrorline(new Line(v3, v2), v18, v19);
                Vector2[] lsline5 = { new Vector2(line6.StartPoint.X, line6.StartPoint.Y), new Vector2(line6.EndPoint.X, line6.EndPoint.Y) };
                fun.drawBLine(dxf, lsline5, 0.3, contour);

                Line line7 = fun.mirrorline(new Line(v1, v2), v16, v17);
                Vector2[] lsline7 = { new Vector2(line7.StartPoint.X, line7.StartPoint.Y), new Vector2(line7.EndPoint.X, line7.EndPoint.Y) };
                fun.drawBLine(dxf, lsline7, 0.3, contour);
                Line line8 = fun.mirrorline(new Line(v3, v2), v16, v17);
                Vector2[] lsline8 = { new Vector2(line8.StartPoint.X, line8.StartPoint.Y), new Vector2(line8.EndPoint.X, line8.EndPoint.Y) };
                fun.drawBLine(dxf, lsline8, 0.3, contour);

                Vector2 v4 = new Vector2(line4.EndPoint.X, line4.EndPoint.Y);
                Vector2 v5 = new Vector2(line3.EndPoint.X, line3.EndPoint.Y);
                Vector2 v6 = new Vector2(line3.StartPoint.X, line3.StartPoint.Y);
                Vector2 v7 = new Vector2(line6.StartPoint.X, line6.StartPoint.Y);
                Vector2 v8 = new Vector2(line6.EndPoint.X, line6.EndPoint.Y);
                Vector2 v9 = new Vector2(line5.StartPoint.X, line5.StartPoint.Y);
                Vector2 v10 = new Vector2(line8.StartPoint.X, line8.StartPoint.Y);
                Vector2 v11 = new Vector2(line7.EndPoint.X, line7.EndPoint.Y);
                Vector2 v12 = new Vector2(line7.StartPoint.X, line7.StartPoint.Y);

                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.3, contour);

                Vector2[] Line10 = { v12, v1 };
                fun.drawBLine(dxf, Line10, 0.3, contour);
                Vector2[] Line11 = { v6, v7 };
                fun.drawBLine(dxf, Line11, 0.3, contour);
                Vector2[] Line12 = { v9, v10 };
                fun.drawBLine(dxf, Line12, 0.3, contour);

                Circle circle00 = new Circle(v13, IC / 2);
                circle00.Layer = center;
                dxf.AddEntity(circle00);


                Vector2 v20 = new Vector2(v15.X + IC, v15.Y);
                Vector2 v21 = new Vector2(v20.X - S / 2 * Math.Sin(An_1), v20.Y + S / 2 * Math.Cos(An_1));
                Vector2 v23 = new Vector2(v20.X - S, v20.Y);
                Vector2 v22 = new Vector2(v23.X - S / 2 * Math.Cos(EPSR_1 - An_1), v23.Y + S / 2 * Math.Sin(EPSR_1 - An_1));
                Vector2 v24 = new Vector2(v12.X + 2 * L, v12.Y);
                Vector2 v25 = new Vector2(v24.X, v24.Y + L);
                Vector2 v26 = new Vector2(v25.X - S, v25.Y - S * Math.Tan(AS_1));
                Vector2 v27 = new Vector2(v24.X - S, v24.Y + S * Math.Tan(AS_1));

                Vector2 v28 = new Vector2(v24.X - 3, v24.Y);

                Vector2 v29 = new Vector2(v15.X + 5, v15.Y);
                Vector2 v30 = new Vector2(v12.X + 1.31, v12.Y + 0.31);
                Vector2 v31 = new Vector2(v15.X + 12.51, v15.Y - 8.37);

                List<Vector3> points00 = new List<Vector3>
                {
                  new Vector3(v22.X,v22.Y , 0),
                  new Vector3(v22.X+1,v22.Y+0.5 , 0),
                  new Vector3(v22.X+2,v22.Y , 0),


                  new Vector3(v21.X ,v21.Y, 0),


                };

                Spline spline00 = new Spline(points00);
                spline00.Layer = contour;
                DxfDocument doc00 = new DxfDocument();
                dxf.AddEntity(spline00);

                Vector2[] Line13 = { v23, v20 };
                fun.drawBLine(dxf, Line13, 0.3, contour);
                Vector2[] Line14 = { v23, v22 };
                fun.drawBLine(dxf, Line14, 0.3, contour);
                Vector2[] Line15 = { v20, v21 };
                fun.drawBLine(dxf, Line15, 0.3, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v25));
                poly1.Vertexes.Add(new LwPolylineVertex(v26));
                poly1.Vertexes.Add(new LwPolylineVertex(v27));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                //            poly1.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);


                //标注
                LinearDimension dim8 = new LinearDimension(new Line(v10, v11), offset, 235, dimensionStyle);
                dim8.UserText = "≈1";
                dxf.AddEntity(dim8);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v10, v29), offset, "37°30′", textheight);
                fun.jdbz1(dxf, new Line(v20, v23), new Line(v20, v11), offset + 3, "15°±1°", textheight);
                fun.jdbz1(dxf, new Line(v24, v27), new Line(v24, v28), offset + 5, "11°±1°", textheight);

                // Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(v10, v15), new Line(v10, v29), offset, dimensionStyle);
                // angdim2.UserText = "37°30′";
                // dxf.AddEntity(angdim2);
                //  Angular2LineDimension angdim6 = new Angular2LineDimension(new Line(v20, v23), (new Line(v20, v11)), offset + 3, dimensionStyle);
                //  angdim6.UserText = "15°±1°";
                // dxf.AddEntity(angdim6);

                // Angular2LineDimension angdim7 = new Angular2LineDimension(new Line(v24, v27), (new Line(v24, v28)), offset + 5, dimensionStyle);
                // angdim7.UserText = "11°±1°";
                //  dxf.AddEntity(angdim7);
                LinearDimension dim1 = new LinearDimension(new Line(v4, v9), offset, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v6), offset, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v14, v15), offset - 3, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);
                LinearDimension dim4 = new LinearDimension(new Line(v17, v12), offset, 120, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);
                // LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                //dim5.UserText = "m";
                //dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v25, v26), offset + 2, 360, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);
                LinearDimension dim7 = new LinearDimension(new Line(v11, v12), offset, 197, dimensionStyle);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v12, v17), offset + 3, "εr", textheight);
                fun.jdbz1(dxf, new Line(v30, v9), new Line(v30, v31), offset, "xr＝75°", textheight);
                fun.jdbz1(dxf, new Line(v3, v4), new Line(v12, v11), offset + 19, "φ", textheight);





            }

            if (KRINS != 0 && AN == 20)
            {

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));




                Vector2 v14 = new Vector2(v3.X, v1.Y + L / 2);
                Vector2 v15 = new Vector2(v14.X + L, v14.Y);
                Vector2 v16 = new Vector2(v14.X + L / 2, v1.Y + L);
                Vector2 v17 = new Vector2(v16.X, v16.Y - L);
                Vector2 v13 = new Vector2(v14.X + L / 2, v14.Y);
                Vector2 v18 = new Vector2(v3.X, v1.Y + L);
                Vector2 v19 = new Vector2(v3.X + L, v1.Y);


                Line line3 = fun.mirrorline(new Line(v1, v2), v14, v15);
                Vector2[] lsline1 = { new Vector2(line3.StartPoint.X, line3.StartPoint.Y), new Vector2(line3.EndPoint.X, line3.EndPoint.Y) };

                Line line4 = fun.mirrorline(new Line(v2, v3), v14, v15);
                Vector2[] lsline2 = { new Vector2(line4.StartPoint.X, line4.StartPoint.Y), new Vector2(line4.EndPoint.X, line4.EndPoint.Y) };



                Line line5 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsline4 = { new Vector2(line5.StartPoint.X, line5.StartPoint.Y), new Vector2(line5.EndPoint.X, line5.EndPoint.Y) };

                Line line6 = fun.mirrorline(new Line(v3, v2), v18, v19);
                Vector2[] lsline5 = { new Vector2(line6.StartPoint.X, line6.StartPoint.Y), new Vector2(line6.EndPoint.X, line6.EndPoint.Y) };


                Line line7 = fun.mirrorline(new Line(v1, v2), v16, v17);
                Vector2[] lsline7 = { new Vector2(line7.StartPoint.X, line7.StartPoint.Y), new Vector2(line7.EndPoint.X, line7.EndPoint.Y) };

                Line line8 = fun.mirrorline(new Line(v3, v2), v16, v17);
                Vector2[] lsline8 = { new Vector2(line8.StartPoint.X, line8.StartPoint.Y), new Vector2(line8.EndPoint.X, line8.EndPoint.Y) };


                Vector2 v4 = new Vector2(line4.EndPoint.X, line4.EndPoint.Y);
                Vector2 v5 = new Vector2(line3.EndPoint.X, line3.EndPoint.Y);
                Vector2 v6 = new Vector2(line3.StartPoint.X, line3.StartPoint.Y);
                Vector2 v7 = new Vector2(line6.StartPoint.X, line6.StartPoint.Y);
                Vector2 v8 = new Vector2(line6.EndPoint.X, line6.EndPoint.Y);
                Vector2 v9 = new Vector2(line5.StartPoint.X, line5.StartPoint.Y);
                Vector2 v10 = new Vector2(line8.StartPoint.X, line8.StartPoint.Y);
                Vector2 v11 = new Vector2(line7.EndPoint.X, line7.EndPoint.Y);
                Vector2 v12 = new Vector2(line7.StartPoint.X, line7.StartPoint.Y);

                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.3, contour);

                Vector2[] Line10 = { v12, v1 };
                fun.drawBLine(dxf, Line10, 0.3, contour);
                Vector2[] Line11 = { v6, v7 };
                fun.drawBLine(dxf, Line11, 0.3, contour);
                Vector2[] Line12 = { v9, v10 };
                fun.drawBLine(dxf, Line12, 0.3, contour);

                Vector2[] Line13 = { v4, v6 };
                fun.drawBLine(dxf, Line13, 0.3, contour);
                Vector2[] Line14 = { v7, v9 };
                fun.drawBLine(dxf, Line14, 0.3, contour);
                Vector2[] Line15 = { v1, v3 };
                fun.drawBLine(dxf, Line15, 0.3, contour);
                Vector2[] Line16 = { v12, v10 };
                fun.drawBLine(dxf, Line16, 0.3, contour);



                Circle circle00 = new Circle(v13, IC / 2);
                circle00.Layer = center;
                dxf.AddEntity(circle00);


                Vector2 v20 = new Vector2(v15.X + IC, v15.Y);
                Vector2 v21 = new Vector2(v20.X - S / 2 * Math.Sin(An_1), v20.Y + S / 2 * Math.Cos(An_1));
                Vector2 v23 = new Vector2(v20.X - S, v20.Y);
                Vector2 v22 = new Vector2(v23.X - S / 2 * Math.Cos(EPSR_1 - An_1), v23.Y + S / 2 * Math.Sin(EPSR_1 - An_1));
                Vector2 v24 = new Vector2(v12.X + 2 * L, v12.Y);
                Vector2 v25 = new Vector2(v24.X, v24.Y + L);
                Vector2 v26 = new Vector2(v25.X - S, v25.Y - S * Math.Tan(AS_1));
                Vector2 v27 = new Vector2(v24.X - S, v24.Y + S * Math.Tan(AS_1));

                Vector2 v28 = new Vector2(v24.X - 3, v24.Y);

                Vector2 v29 = new Vector2(v15.X + 5, v15.Y);
                Vector2 v30 = new Vector2(v12.X + 1.31, v12.Y + 0.31);
                Vector2 v31 = new Vector2(v15.X + 12.51, v15.Y - 8.37);

                List<Vector3> points00 = new List<Vector3>
           {
                 new Vector3(v22.X,v22.Y , 0),
               new Vector3(v22.X+1,v22.Y+0.5 , 0),
               new Vector3(v22.X+2,v22.Y , 0),


                  new Vector3(v21.X ,v21.Y, 0),


            };

                Spline spline00 = new Spline(points00);
                spline00.Layer = contour;
                DxfDocument doc00 = new DxfDocument();
                dxf.AddEntity(spline00);

                Vector2[] Line113 = { v23, v20 };
                fun.drawBLine(dxf, Line113, 0.3, contour);
                Vector2[] Line114 = { v23, v22 };
                fun.drawBLine(dxf, Line114, 0.3, contour);
                Vector2[] Line115 = { v20, v21 };
                fun.drawBLine(dxf, Line115, 0.3, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v25));
                poly1.Vertexes.Add(new LwPolylineVertex(v26));
                poly1.Vertexes.Add(new LwPolylineVertex(v27));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                //            poly1.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);





                LinearDimension dim1 = new LinearDimension(new Line(v4, v9), offset, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v6), offset, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v14, v15), offset - 3, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);
                LinearDimension dim4 = new LinearDimension(new Line(v17, v12), offset, 120, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);
                // LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                //dim5.UserText = "m";
                //dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v25, v26), offset + 2, 360, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);
                LinearDimension dim7 = new LinearDimension(new Line(v11, v12), offset, 197, dimensionStyle);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v12, v17), offset + 3, "εr", textheight);
                fun.jdbz1(dxf, new Line(v30, v9), new Line(v30, v31), offset, "xr＝75°", textheight);
                fun.jdbz1(dxf, new Line(v3, v4), new Line(v12, v11), offset + 19, "φ", textheight);
                fun.jdbz1(dxf, new Line(v20, v23), new Line(v20, v11), offset + 3, "20°±30°", textheight);
                fun.jdbz1(dxf, new Line(v24, v27), new Line(v24, v28), offset + 5, "20°±30°", textheight);



            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);



        }


        public static void ThreadingInsert(Dictionary<string, Object> data)    //螺纹刀片
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;

            double pi = Math.PI;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }
            double ic = Convert.ToDouble(data["ic"]);
            double s = Convert.ToDouble(data["s"]);
            double pdx = Convert.ToDouble(data["pdx"]);
            double pdy = Convert.ToDouble(data["pdy"]);
            double re = Convert.ToDouble(data["re"]);
            double s1 = Convert.ToDouble(data["s1"]);
            double d1 = Convert.ToDouble(data["d1"]);
            double lbb = Convert.ToDouble(data["lbb"]);
            double gan = Convert.ToDouble(data["gan"]) * pi / 180;
            double pnl = Convert.ToDouble(data["pnl"]) * pi / 180;
            double pnr = Convert.ToDouble(data["pnr"]) * pi / 180;
            double tp = Convert.ToDouble(data["tp"]);
            double pdpt = Convert.ToDouble(data["pdpt"]);
            double pdpt1 = Convert.ToDouble(data["pdpt1"]);
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            string path = Convert.ToString(data["path"]);

            double le = 2 * ic * Math.Cos(pi / 6);
            double pna = pnl + pnr;
            double ang1 = 30 * pi / 180;
            double ang2 = 60 * pi / 180;
            double ang3 = 120 * pi / 180;

            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, ang2, ic / 2);
            Vector2 p2 = fun.Polar(p1, ang1, le);
            Vector2 p3 = fun.Polar(p1, pi / 2, le);
            Vector2 p6 = new Vector2(p3.X - pdx, p3.Y - pdy);
            double ang4 = fun.CalAngle(p0, p6);
            double length1 = fun.CalDistance(p0, p6);
            Vector2 p4 = fun.Polar(p0, ang4 + ang3, length1);
            Vector2 p5 = fun.Polar(p0, ang4 - ang3, length1);
            Vector2 c05 = fun.Polar(p6, 1.5 * pi - pnl, pdpt / Math.Cos(pnl));
            Vector2 c06 = new Vector2(p1.X, c05.Y);
            Vector2 c07 = new Vector2(p1.X, p6.Y - lbb);
            Vector2 c01 = fun.Inters(p2, p3, c06, fun.Polar(c07, 0, 100));
            Vector2 c04 = fun.Polar(p6, 1.5 * pi + pnr, pdpt1 / Math.Cos(pnr));
            Vector2 c03 = fun.Polar(c04, 0, 0.7);
            Vector2 c02 = fun.Inters(p2, p3, c03, fun.Polar(c03, ang2, 100));
            double length2 = fun.CalDistance(c01, p3);
            Vector2 c11 = fun.Polar(p2, pi + ang1, length2);
            Vector2 c21 = fun.Polar(p1, pi / 2, length2);
            double length3 = fun.CalDistance(c02, p3);
            Vector2 c12 = fun.Polar(p2, pi + ang1, length3);
            Vector2 c22 = fun.Polar(p1, pi / 2, length3);
            double length4 = fun.CalDistance(c06, p3);
            Vector2 c16 = fun.Polar(p2, pi - ang1, length4);
            Vector2 c26 = fun.Polar(p1, ang1, length4);
            double length5 = fun.CalDistance(c07, p3);
            Vector2 c17 = fun.Polar(p2, pi - ang1, length5);
            Vector2 c27 = fun.Polar(p1, ang1, length5);
            double angular1 = fun.CalAngle(p0, c03);
            double dis1 = fun.CalDistance(p0, c03);
            Vector2 c13 = fun.Polar(p0, angular1 - ang3, dis1);
            Vector2 c23 = fun.Polar(p0, angular1 + ang3, dis1);
            double angular2 = fun.CalAngle(p0, c04);
            double dis2 = fun.CalDistance(p0, c04);
            Vector2 c14 = fun.Polar(p0, angular2 - ang3, dis2);
            Vector2 c24 = fun.Polar(p0, angular2 + ang3, dis2);
            double angular3 = fun.CalAngle(p0, c05);
            double dis3 = fun.CalDistance(p0, c05);
            Vector2 c15 = fun.Polar(p0, angular3 - ang3, dis3);
            Vector2 c25 = fun.Polar(p0, angular3 + ang3, dis3);
            Vector2 p6p = fun.Polar(p6, 1.5 * pi + pna / 2, re / Math.Sin(pna / 2));
            Vector2 p6z = fun.Polar(p6, 1.5 * pi - pnl, re / Math.Tan(pna / 2));
            Vector2 p6y = fun.Polar(p6, 1.5 * pi + pnr, re / Math.Tan(pna / 2));
            double angular4 = fun.CalAngle(p0, p6p);
            double dis4 = fun.CalDistance(p0, p6p);
            Vector2 p5p = fun.Polar(p0, angular4 - ang3, dis4);
            Vector2 p4p = fun.Polar(p0, angular4 + ang3, dis4);
            double angular5 = fun.CalAngle(p0, p6z);
            double dis5 = fun.CalDistance(p0, p6z);
            Vector2 p5z = fun.Polar(p0, angular5 - ang3, dis5);
            Vector2 p4z = fun.Polar(p0, angular5 + ang3, dis5);
            double angular6 = fun.CalAngle(p0, p6y);
            double dis6 = fun.CalDistance(p0, p6y);
            Vector2 p5y = fun.Polar(p0, angular6 - ang3, dis6);
            Vector2 p4y = fun.Polar(p0, angular6 + ang4, dis6);

            Vector2 p20 = fun.Polar(p0, 0, 3 * le);
            Vector2 p21 = new Vector2(p20.X, p6.Y);
            Vector2 p22 = fun.Polar(p21, pi, s);
            Vector2 p24 = new Vector2(p20.X, p4.Y);
            Vector2 p23 = fun.Polar(p24, pi, s);

            //inserthole(dxf, p0, p20,p21, scale, data);

            Line line01 = new Line(c01, c07);
            Line line02 = new Line(c01, c02);
            Line line03 = new Line(c02, c03);
            Line line04 = new Line(c03, c04);
            Line line05 = new Line(c04, p6y);
            Line line06 = new Line(p6z, c06);
            Line line07 = new Line(c06, c07);
            Line line08 = new Line(c07, c21);
            Line line11 = new Line(c11, c17);
            Line line12 = new Line(c11, c12);
            Line line13 = new Line(c12, c13);
            Line line14 = new Line(c13, c14);
            Line line15 = new Line(c14, p5y);
            Line line16 = new Line(p5z, c16);
            Line line17 = new Line(c16, c17);
            Line line18 = new Line(c17, c01);
            Line line21 = new Line(c21, c27);
            Line line22 = new Line(c21, c22);
            Line line23 = new Line(c22, c23);
            Line line24 = new Line(c23, c24);
            Line line25 = new Line(c24, p4y);
            Line line26 = new Line(p4z, c26);
            Line line27 = new Line(c26, c27);
            Line line28 = new Line(c27, c11);
            Arc arc01 = fun.DrawArc(p6y, p6p, p6z);
            Arc arc11 = fun.DrawArc(p5y, p5p, p5z);
            Arc arc21 = fun.DrawArc(p4y, p4p, p4z);
            line01.Layer = contour;
            line02.Layer = contour;
            line03.Layer = contour;
            line04.Layer = contour;
            line05.Layer = contour;
            line06.Layer = contour;
            line07.Layer = contour;
            line08.Layer = contour;
            line11.Layer = contour;
            line12.Layer = contour;
            line13.Layer = contour;
            line14.Layer = contour;
            line15.Layer = contour;
            line16.Layer = contour;
            line17.Layer = contour;
            line18.Layer = contour;
            line21.Layer = contour;
            line22.Layer = contour;
            line23.Layer = contour;
            line24.Layer = contour;
            line25.Layer = contour;
            line26.Layer = contour;
            line27.Layer = contour;
            line28.Layer = contour;
            arc01.Layer = contour;
            arc11.Layer = contour;
            arc21.Layer = contour;
            dxf.AddEntity(line01);
            dxf.AddEntity(line02);
            dxf.AddEntity(line03);
            dxf.AddEntity(line04);
            dxf.AddEntity(line04);
            dxf.AddEntity(line05);
            dxf.AddEntity(line06);
            dxf.AddEntity(line07);
            dxf.AddEntity(line08);
            dxf.AddEntity(line11);
            dxf.AddEntity(line12);
            dxf.AddEntity(line13);
            dxf.AddEntity(line14);
            dxf.AddEntity(line14);
            dxf.AddEntity(line15);
            dxf.AddEntity(line16);
            dxf.AddEntity(line17);
            dxf.AddEntity(line18);
            dxf.AddEntity(line21);
            dxf.AddEntity(line22);
            dxf.AddEntity(line23);
            dxf.AddEntity(line24);
            dxf.AddEntity(line24);
            dxf.AddEntity(line25);
            dxf.AddEntity(line26);
            dxf.AddEntity(line27);
            dxf.AddEntity(arc01);
            dxf.AddEntity(arc11);
            dxf.AddEntity(arc21);

            Circle circle1 = new Circle(p0, ic / 2);
            circle1.Layer = refin;
            circle1.Linetype = Linetype.DashDot;
            dxf.AddEntity(circle1);

            Circle circle2 = new Circle(p0, d1 / 2);
            circle2.Layer = contour;
            dxf.AddEntity(circle2);

            double isframe = Convert.ToDouble(data["isframe"]);
            if (isframe == 1)
            {
                Frame.frameA4X(dxf, new Vector2(p0.X - 100, p0.Y + 100));
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        //刀片孔型
        public static void inserthole(DxfDocument dxf, Vector2 p0, Vector2 v2, Vector2 v3, Vector2 p20, Vector2 p21, double scale, Dictionary<string, Object> data)//v2为断屑槽最下面的点，v3为断屑槽最上面的点
        {
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double fhcsd = 0;
            double fhcsr = 0;
            double fhcsa = 0;

            double ic = Convert.ToDouble(data["ic"]) * scale;
            if (ic == 0)
            {
                ic = Convert.ToDouble(data["w1"]) * scale;
            }
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);

            if (ifs == 1)//无孔
            {

            }
            else if (ifs == 2)//
                              //柱孔
            {

            }
            else if (ifs == 3)//45°~60°沉头孔
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsr = (fhcsd - d1) / 2.0;
            }
            else if (ifs == 4)//75°~90°沉头孔
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsa = Convert.ToDouble(data["fhcsa"]);
            }
            else if (ifs == 0)
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsa = Convert.ToDouble(data["fhcsa"]);
            }
            else
            {
                Console.WriteLine("error,ifs");
                Console.ReadKey();
            }

            if (ifs == 1 && cb == 0)  //无孔无断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] type = new String[100];
                Line[] line = new Line[100];
                int numst = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < numst; i++)
                {
                    type[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (type[i] == "Line")
                    {
                        line[i] = (Line)poly1.Explode()[i];
                    }
                }

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }




                fun.hatchsubofline(dxf, type, numst, 45, 5 * scale, line, hatching);

            }
            else if (ifs == 1 && cb == 1)  //无孔单面断屑槽
            {

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 p25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 p26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(p25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(p26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes[3].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

            }
            else if (ifs == 1 && cb == 2)  //无孔双面断屑槽
            {

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 p25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 p26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 p27 = new Vector2(p22.X, p25.Y);
                Vector2 p28 = new Vector2(p22.X, p26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(p25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(p26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(p28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(p27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);

                //爆炸
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly1.Vertexes[3].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

            }
            else if (ifs == 2 && cb == 0)  //A型孔无断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p29.X - 0.5, p29.Y + 0.5);
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p31.X - 0.5, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注
                fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {
                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 2 && cb == 1)  //A型孔单面断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p26.X, p20.Y - (d1 / 2));
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p28.X, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);


                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);


                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //poly1.Vertexes.Add(new LwPolylineVertex(v25));
                //poly1.Vertexes.Add(new LwPolylineVertex(p21));
                // poly1.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                //poly2.Vertexes.Add(new LwPolylineVertex(v26));
                //poly1.Vertexes[0].Bulge = Math.Tan(-90 * pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[6].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 2 && cb == 2)  //A型孔双面断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p29.X - 0.5, p29.Y + 0.5);
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p31.X - 0.5, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);



                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);



                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);



                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[7].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 0)  //45°-60°沉头孔无断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);


                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 1)  //45°-60°沉头孔单面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes[2].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p35));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p36));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);


                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 2)  //45°-60°沉头孔双面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);


                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes[2].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[4].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes[8].Bulge = Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p35));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p36));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[4].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 0)  //75°-90°沉头孔无断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5 * scale, hline1, hatching);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype2, hnumst2, 45, 5 * scale, hline2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 1)  //75°-90°沉头孔单面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);


                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p33));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[7].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 2)  //75°-90°沉头孔双面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);
                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);



                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[8].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p33));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[8].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else  //D型孔
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p27 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p28 = new Vector2(p22.X, p27.Y + 0.5);
                Vector2 p26 = fun.Inters(p27, fun.Polar(p27, 0, 100), p25, fun.Polar(p25, (pi + fhcsa / 2), 100));
                Vector2 p29 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p32 = new Vector2(p22.X, p31.Y - 0.5);
                Vector2 p30 = new Vector2(p26.X, p31.Y);

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5 * scale, hline1, hatching);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype2, hnumst2, 45, 5 * scale, hline2, hatching);

                Vector2[] lineh1 = { p28, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p27, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p26, p30 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p25, p29 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0, "tzd", "φ0.1", "A");
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);


        }

        //刀片孔型1（不含公差）
        public static void inserthole1(DxfDocument dxf, Vector2 p0, Vector2 v2, Vector2 v3, Vector2 p20, Vector2 p21, double scale, Dictionary<string, Object> data)//v2为断屑槽最下面的点，v3为断屑槽最上面的点
        {
            //图层
            Layer contour = fun.SetLayer("contour");//轮廓层
            Layer dimensioning = fun.SetLayer("dimensioning");//尺寸层
            Layer refin = fun.SetLayer("refin");//基准线/内轮廓/虚线
            Layer center = fun.SetLayer("center");//中心线
            Layer textlayer = fun.SetLayer("textlayer");//文本层
            Layer hatching = fun.SetLayer("hatching");//填充层
            Layer additionalline = fun.SetLayer("additionalline");//附加线
            Layer cutting = fun.SetLayer("cutting");//切削层




            double textheight = 3.5;

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double fhcsd = 0;
            double fhcsr = 0;
            double fhcsa = 0;

            double ic = Convert.ToDouble(data["ic"]) * scale;
            if (ic == 0)
            {
                ic = Convert.ToDouble(data["w1"]) * scale;
            }
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);

            if (ifs == 1)//无孔
            {

            }
            else if (ifs == 2)//
                              //柱孔
            {

            }
            else if (ifs == 3)//45°~60°沉头孔
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsr = (fhcsd - d1) / 2.0;
            }
            else if (ifs == 4)//75°~90°沉头孔
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsa = Convert.ToDouble(data["fhcsa"]);
            }
            else if (ifs == 0)
            {
                // fhcsd = Convert.ToDouble(data["fhcsd"]) * scale;
                fhcsd = 1.2 * d1;
                fhcsa = Convert.ToDouble(data["fhcsa"]);
            }
            else
            {
                Console.WriteLine("error,ifs");
                Console.ReadKey();
            }

            if (ifs == 1 && cb == 0)  //无孔无断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] type = new String[100];
                Line[] line = new Line[100];
                int numst = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < numst; i++)
                {
                    type[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (type[i] == "Line")
                    {
                        line[i] = (Line)poly1.Explode()[i];
                    }
                }

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }




                fun.hatchsubofline(dxf, type, numst, 45, 5 * scale, line, hatching);

            }
            else if (ifs == 1 && cb == 1)  //无孔单面断屑槽
            {

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 p25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 p26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(p25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(p26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes[3].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

            }
            else if (ifs == 1 && cb == 2)  //无孔双面断屑槽
            {

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 p25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 p26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 p27 = new Vector2(p22.X, p25.Y);
                Vector2 p28 = new Vector2(p22.X, p26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(p25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(p26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(p28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(p27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);

                //爆炸
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly1.Vertexes[3].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

            }
            else if (ifs == 2 && cb == 0)  //A型孔无断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p29.X - 0.5, p29.Y + 0.5);
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p31.X - 0.5, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;

                double height = textheight;
                double arrowsize = textheight;
                double exline = 0.5 * scale;

                //标注
                //fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                    /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");*/
                }
                else
                {
                    if (d1tc == 0)
                    {
                        fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                        /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);*/
                    }
                    if (d1tc != 0)
                    {
                        fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                        /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);*/
                    }
                }
            }
            else if (ifs == 2 && cb == 1)  //A型孔单面断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p26.X, p20.Y - (d1 / 2));
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p28.X, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);


                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);


                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //poly1.Vertexes.Add(new LwPolylineVertex(v25));
                //poly1.Vertexes.Add(new LwPolylineVertex(p21));
                // poly1.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                //poly2.Vertexes.Add(new LwPolylineVertex(v26));
                //poly1.Vertexes[0].Bulge = Math.Tan(-90 * pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[6].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;

                double height = 3.5;
                double arrowsize = textheight;
                double exline = 0.5 * scale;

                //标注

                //fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                    /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");*/
                }
                else
                {

                    if (d1tc == 0)
                    {
                        fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                        /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);*/
                    }
                    if (d1tc != 0)
                    {
                        fun.dimrot1(dxf, p27, p31, 90, s * 1.5, 0.1, height, arrowsize, exline, "D1=" + Math.Round(d1, 3), "", "");
                        /*LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);*/
                    }
                }
            }
            else if (ifs == 2 && cb == 2)  //A型孔双面断屑槽
            {
                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p25 = new Vector2(p20.X, p20.Y + (d1 / 2 + 0.5));
                Vector2 p26 = new Vector2(p20.X - 0.5, p20.Y + (d1 / 2));
                Vector2 p27 = fun.Polar(p26, pi, (s - 1.0));
                Vector2 p28 = new Vector2(p27.X - 0.5, p27.Y + 0.5);
                Vector2 p29 = new Vector2(p20.X, p20.Y - (d1 / 2 + 0.5));
                Vector2 p30 = new Vector2(p29.X - 0.5, p29.Y + 0.5);
                Vector2 p31 = fun.Polar(p30, pi, (s - 1.0));
                Vector2 p32 = new Vector2(p31.X - 0.5, p31.Y - 0.5);
                //Vector2[] pline1 = { p25, p26, p27, p28 };
                //Vector2[] pline2 = { p29, p30, p31, p32 };
                //fun.drawPline(dxf, pline1);
                //fun.drawPline(dxf, pline2);



                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);



                Vector2[] lineh5 = { p28, p32 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);
                Vector2[] lineh6 = { p25, p29 };
                fun.drawBLine(dxf, lineh6, 0.4, contour);
                Vector2[] lineh7 = { p26, p30 };
                fun.drawBLine(dxf, lineh7, 0.4, contour);
                Vector2[] lineh8 = { p27, p31 };
                fun.drawBLine(dxf, lineh8, 0.4, contour);

                fun.drawcircle(dxf, p0, (d1 + 1.0) / 2.0, 0.15, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                //            poly1.SetConstantWidth(0.05);
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);



                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[7].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 0)  //45°-60°沉头孔无断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);


                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 1)  //45°-60°沉头孔单面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes[2].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p35));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p36));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes[5].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);


                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 3 && cb == 2)  //45°-60°沉头孔双面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p27 = fun.Polar(p26, pi, fhcsr);
                Vector2 p28 = new Vector2(p27.X, p27.Y - fhcsr);
                Vector2 p29 = new Vector2(p22.X + 0.5, p28.Y);
                Vector2 p30 = new Vector2(p22.X, p29.Y + 1.0);
                Vector2 p31 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p32 = fun.Polar(p31, pi, (0.25 * d1));
                Vector2 p33 = fun.Polar(p32, pi, fhcsr);
                Vector2 p34 = new Vector2(p28.X, p32.Y + fhcsr);
                Vector2 p35 = new Vector2(p29.X, p34.Y);
                Vector2 p36 = new Vector2(p22.X, p35.Y - 0.5);


                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p31, fun.Polar(p31, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p31, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p30));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes[6].Bulge = Math.Tan(pi / 8);
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                //            poly.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly1, 0.5, contour);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p35));
                poly2.Vertexes.Add(new LwPolylineVertex(p36));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                //            poly1.SetConstantWidth(0.05);
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes[2].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[4].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes[8].Bulge = Math.Tan(pi / 8);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes[0].Bulge = Math.Tan(pi / 8);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p35));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p36));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[4].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes[6].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p26, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p25, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p30, p36 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p29, p35 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p29, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p29, p35), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 0)  //75°-90°沉头孔无断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5 * scale, hline1, hatching);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype2, hnumst2, 45, 5 * scale, hline2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 1)  //75°-90°沉头孔单面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);


                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);
                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p33));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[7].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else if (ifs == 4 && cb == 2)  //75°-90°沉头孔双面断削槽
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p26 = fun.Polar(p25, pi, (0.25 * d1));
                Vector2 p28 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p29 = new Vector2(p22.X, p28.Y + 0.5);
                Vector2 p27 = fun.Inters(p28, fun.Polar(p28, 0, 100), p26, fun.Polar(p26, (pi + (fhcsa * pi) / 360), 100));
                Vector2 p30 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = fun.Polar(p30, pi, (0.25 * d1));
                Vector2 p33 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p34 = new Vector2(p22.X, p33.Y - 0.5);
                Vector2 p32 = fun.Inters(p33, fun.Polar(p33, 0, 100), p31, fun.Polar(p31, (pi - (fhcsa * pi) / 360), 100));
                Vector2 v25 = fun.Polar(p21, -90 * pi / 180, (p21.Y - v3.Y) * 2);
                Vector2 v26 = fun.Polar(p24, 90 * pi / 180, (v2.Y - p24.Y) * 2);
                Vector2 v27 = new Vector2(p22.X, v25.Y);
                Vector2 v28 = new Vector2(p22.X, v26.Y);
                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                String dmccd = Convert.ToString(data["dmccd"]);
                if (!"0".Equals(dmccd))
                {
                    fun.czd(dxf, fun.Polar(p22, -90 * pi / 180, ic / 7), 180, String.Format("{0}", dmccd));
                }
                String kccd = Convert.ToString(data["kccd"]);
                if (!"0".Equals(kccd))
                {
                    Line line00 = new Line(p30, fun.Polar(p30, 0, s / 2));
                    dxf.AddEntity(line00);
                    fun.czd(dxf, fun.Polar(p30, 0 * pi / 180, s / 3), 90, String.Format("{0}", kccd));
                }

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(p21));
                Line01.Vertexes.Add(new LwPolylineVertex(v25));
                Line01.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
                LwPolyline Arc1 = new LwPolyline();
                Arc1.Vertexes.Add(new LwPolylineVertex(v26));
                Arc1.Vertexes.Add(new LwPolylineVertex(p24));
                Arc1.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc1.Layer = additionalline;
                dxf.AddEntity(Arc1);
                LwPolyline Arc2 = new LwPolyline();
                Arc2.Vertexes.Add(new LwPolylineVertex(p23));
                Arc2.Vertexes.Add(new LwPolylineVertex(v28));
                Arc2.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc2.Layer = additionalline;
                dxf.AddEntity(Arc2);
                LwPolyline Arc3 = new LwPolyline();
                Arc3.Vertexes.Add(new LwPolylineVertex(v27));
                Arc3.Vertexes.Add(new LwPolylineVertex(p22));
                Arc3.Vertexes[0].Bulge = Math.Tan(90 * pi / 180 / 4);
                Arc3.Layer = additionalline;
                dxf.AddEntity(Arc3);


                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p29));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);



                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p34));
                poly2.Vertexes.Add(new LwPolylineVertex(p33));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p29));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p28));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p27));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p26));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(p21));
                hatchpoly1.Vertexes[8].Bulge = Math.Tan(-90 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5 * scale, hline1, harc1, hatching);


                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p23));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p34));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p33));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p32));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(p24));
                hatchpoly2.Vertexes[8].Bulge = Math.Tan(90 * pi / 180 / 4);
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[200];
                Line[] hline2 = new Line[200];
                Arc[] harc2 = new Arc[200];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 5 * scale, hline2, harc2, hatching);

                Vector2[] lineh1 = { p29, p34 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p28, p33 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p27, p32 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p26, p31 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);
                Vector2[] lineh5 = { p25, p30 };
                fun.drawBLine(dxf, lineh5, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p28, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p28, p33), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }
            else  //D型孔
            {
                fun.drawcircle(dxf, p0, d1 / 2, 0.4, contour);

                Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
                Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
                Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

                Vector2 p25 = new Vector2(p20.X, p20.Y + (fhcsd / 2));
                Vector2 p27 = new Vector2(p22.X + 0.5, p20.Y + (d1 / 2));
                Vector2 p28 = new Vector2(p22.X, p27.Y + 0.5);
                Vector2 p26 = fun.Inters(p27, fun.Polar(p27, 0, 100), p25, fun.Polar(p25, (pi + fhcsa / 2), 100));
                Vector2 p29 = new Vector2(p20.X, p20.Y - (fhcsd / 2));
                Vector2 p31 = new Vector2(p22.X + 0.5, p20.Y - (d1 / 2));
                Vector2 p32 = new Vector2(p22.X, p31.Y - 0.5);
                Vector2 p30 = new Vector2(p26.X, p31.Y);

                fun.drawcircle(dxf, p0, fhcsd / 2, 0.4, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p21));
                poly1.Vertexes.Add(new LwPolylineVertex(p22));
                poly1.Vertexes.Add(new LwPolylineVertex(p28));
                poly1.Vertexes.Add(new LwPolylineVertex(p27));
                poly1.Vertexes.Add(new LwPolylineVertex(p26));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                //            poly.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5 * scale, hline1, hatching);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p24));
                poly2.Vertexes.Add(new LwPolylineVertex(p23));
                poly2.Vertexes.Add(new LwPolylineVertex(p32));
                poly2.Vertexes.Add(new LwPolylineVertex(p31));
                poly2.Vertexes.Add(new LwPolylineVertex(p30));
                poly2.Vertexes.Add(new LwPolylineVertex(p29));
                poly2.IsClosed = true;
                fun.PolyFill(dxf, poly2, 0.5, contour);

                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                int hnumst2 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly2.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly2.Explode()[i];
                    }
                }

                fun.hatchsubofline(dxf, htype2, hnumst2, 45, 5 * scale, hline2, hatching);

                Vector2[] lineh1 = { p28, p32 };
                fun.drawBLine(dxf, lineh1, 0.4, contour);
                Vector2[] lineh2 = { p27, p31 };
                fun.drawBLine(dxf, lineh2, 0.4, contour);
                Vector2[] lineh3 = { p26, p30 };
                fun.drawBLine(dxf, lineh3, 0.4, contour);
                Vector2[] lineh4 = { p25, p29 };
                fun.drawBLine(dxf, lineh4, 0.4, contour);

                DimensionStyle dimensionStyle = new DimensionStyle("ds");
                dimensionStyle.ArrowSize = textheight;
                dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                dimensionStyle.TextHeight = textheight;
                double offset1 = 10;
                //标注

                //fun.gczyx0(dxf, fun.Polar(p27, 180 * pi / 180, offset1), fun.CalDistance(p20, p21) + 10, 10, 90, 0);
                if (DIM == 0)
                {
                    LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                    fun.dxflinedim(dxf, hdimline1, "D1");
                }
                else
                {

                    if (d1tc == 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}", d1 / scale);
                        dxf.AddEntity(hdimline1);
                    }
                    if (d1tc != 0)
                    {
                        LinearDimension hdimline1 = new LinearDimension(new Line(p27, p31), offset1, 90, dimensionStyle);
                        hdimline1.UserText = String.Format("D1={0}±{1}", d1 / scale, d1tc);
                        dxf.AddEntity(hdimline1);
                    }
                }
            }

            fun.SetLayer(dxf); fun.SetByLayer(dxf);


        }



    }
}
